Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...