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
223 views
in Technique[技术] by (71.8m points)

python - discord.py authorized members


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

1 Answer

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.


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

...