Discord.py - How to make a role specific command?

2019-02-28 11:43发布

问题:

I need to make a command that can only be executed by someone that has a certain role. I searched around on google and youtube to find a answer but came up with nothing

回答1:

You can add a decorator on the command to restrict it to only members with specific roles or permissions. The documentation for it is here. It would look like this:

@bot.command()
@commands.has_role('RoleName')
async def command_name():

Keep in mind that the RoleName string you pass is case sensitive.