Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

python - discord.py authorized members


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

1 Reply

0 votes
by (71.8m points)

If you want to make sure only certain people can execute the command, do the following:

@client.command()
@commands.has_permissions(your_permission=True)  # I'll give a list of permissions down below

Or, alternatively, you can make people with only a certain role can execute a command, do the following:

@client.command()
@commands.has_role('YOUR ROLE HERE')  # This will allow only people with the given role to execute the command

Or you can do this, if you want people with a range of roles to be able to execute the command:

@client.command()
@commands.has_any_role('Role1', 'Role2', 'Role3')  # Anyone with any one or more of these roles can execute the command. You can have more than 3 roles stated, or less. If you only have one stated, then it may be better to use the way above

As stated above, I would provide a list of permissions here. These are a few:

@commands.has_permissions(manage_messages=True, kick_members=True, ban_members=True)

Permissions are usually just the permissions that you may give a role, but an underscore replacing the spaces between the words.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...