简体   繁体   中英

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.

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.

@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'

工作图像

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM