简体   繁体   English

我怎样才能使它只有具有特定角色的成员才能执行命令?

[英]How can I make it so only members with a specific role can execute a command?

My question may seem common, but this time there's a twist.我的问题可能看起来很常见,但这次有一个转折点。 I need it to require a role AND one of the specific roles instead of just one of the few roles.我需要它来要求一个角色和一个特定角色,而不仅仅是少数几个角色之一。 Here's the code that I tried that didn't work这是我尝试过但不起作用的代码

@bot.command()
@commands.has_any_role("Buffalo Bills")
@commands.has_any_role("Franchise Owner", "General Manager", "Head Coach", "Assistant Coach")

then from there, the rest of my command.然后从那里,我命令的 rest。

So here's one way you could do it.所以这是你可以做到的一种方法。 Using @commands.has_role() and @commands.has_any_role , you can ensure that the user has one specific role as well as one of the roles given.使用@commands.has_role()@commands.has_any_role ,您可以确保用户具有一个特定角色以及给定的角色之一。

@client.command()
@commands.has_role('Must Have Role')
@commands.has_any_role('Role One', 'Role Two')
async def role_test(ctx):
    await ctx.send("Hey this worked") 
# This would only send if the user has 'Must Have Role' and either 'Role One' or 'Role Two'

工作图像

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 事件可以执行命令吗? 如果是这样,我怎样才能让我的人这样做? - Can an event execute a command? If so, how can I make my one do so? 我如何还可以检查成员是否具有特定角色是 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? 如何做到这一点,这样我就只能读取特定单词的文本文件? - How do I make it so I can read a text file for only specific words? 我将如何做到这一点,以便个人是唯一可以使用 discord 机器人运行命令的人? - How would I make it so that an individual person is the only one who can run a command with a discord bot? Discord.py | 如何为成员添加角色? - Discord.py | How can i add role to members? 如何制作只能触发一次的命令? - How can I make a command that can only be triggered once? 如何使用户在重新进入 discord 服务器时不会删除静音角色? - How can I make it so that the user does not remove mute role when re-entering the discord server? 如果还没有静音角色,如何使静音命令添加静音角色? (discord.py) - How can I make the mute command add a Muted role if there isn't already one? (discord.py) 如何使不和谐的机器人根据人员在命令中输入的内容来创建角色 - How can I make a discord bot create a role based on what the person types in the command 如何使 python 可以在命令提示符中检查 SystemError - How can I make it so that python can check a SystemError in the command prompt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM