So, I was trying to make a check function when if you have a role in a list of role it will work (with a user dev id on the function aswell to bypass it) but it didn't work out.
mod_roles = [792816637488281642,
792626568488713617,
827277277488728524]
devs = [341837496763678731,
382761658858276714]
def is_mod():
def predicate(ctx):
if ctx.author.id not in config.devs \
and any(role.id not in config.mod_roles for role in ctx.author.roles):
raise
else:
return True
return commands.check(predicate)
@checks.is_mod()
@bot.command()
async def test(ctx):
await ctx.send("testing")
When I ran it:
discord.ext.commands.errors.CheckFailure: The check functions for command test failed.
If you want to keep your lists of IDs and only allow them to execute a command you can built in a different check.
For that we have to check the id
of the command author
.
Have a look at the following code:
mod_roles = [] # Insert IDs
devs = [] # Insert IDs
@bot.command()
async def test(ctx):
user = ctx.author.id # Check the ID of the user
if user in mod_roles or devs: # If mod or dev
await ctx.send("Testing")
else:
return await ctx.send("You are not allowed to use the command") # No Mod/Dev
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.