[英]How to check if the author have a specific role in list of roles?
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.因此,我试图检查 function 如果您在角色列表中有一个角色,它将起作用(在 function 上还有一个用户开发 ID 以绕过它),但它没有成功。
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.如果你想保留你的 ID 列表并且只允许他们执行一个命令,你可以建立一个不同的检查。
For that we have to check the id
of the command author
.为此,我们必须检查命令author
的id
。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.