简体   繁体   English

如何检查作者是否在角色列表中具有特定角色?

[英]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 .为此,我们必须检查命令authorid

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.

相关问题 如何检查消息作者的角色 + 如何在 Discord.py 上 DM 特定角色? - How can I check the role of a message author + How do I DM specific roles on Discord.py? 从角色ID列表中检查命令作者是否具有特定角色 - Check if the command author has a specific role from a list of role IDs 如何检查用户是否在角色列表中具有特定角色? (discord.py) - How to check if a user has a specific role in a list of roles? (discord.py) 如何使用discord.py检查用户是否在角色列表中拥有角色? - How to check if a user has a role in a list of roles with discord.py? 如何检查作者在x服务器中是否具有x角色? - How to check if the author has x role in x server? 我如何还可以检查成员是否具有特定角色是 if 语句? 仅当您具有特定角色时才需要 elif 执行? - how can I also check if a member has a specific role is an if statement? need the elif to only execute if you have a specific role? 如果作者没有特定角色,如何制作一个不和谐的bot来删除带有附件的邮件 - How to make a discord bot which deletes messages with attachments if the author doesn't have certain roles 如何检查用户是否具有角色 ID 的特定角色 - how do I check if a user has a specific role with role id Python discord 机器人检查所有用户的特定角色,该角色也具有特定角色 - Python discord bot to check all users for a specific role that also HAVE a specific role 如何检查所有元组在python列表中是否具有特定值 - How to check if all tuples have a specific value in a python list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM