![](/img/trans.png)
[英]How can I check the role of a message author + How do I DM specific roles on Discord.py?
[英]How to check if the author have a specific role in list of roles?
因此,我试图检查 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")
当我运行它时:
discord.ext.commands.errors.CheckFailure: The check functions for command test failed.
如果你想保留你的 ID 列表并且只允许他们执行一个命令,你可以建立一个不同的检查。
为此,我们必须检查命令author
的id
。
看看下面的代码:
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.