Python code snippet with the code needed to give a Discord bot the functionality to add roles to the user who invoked the slash command.
- Assign the bot's Token to the constant TOKEN.
- Add the IDs of the Discord servers on which the bot will act to GUILD_IDS (list of int).
- Add as many
create_choice
as needed with theirname
andvalue
parameters.
- Only the functionality of adding roles is included. To remove roles, a similar function would be used by modifying the messages and replacing the
add_roles
method (line 53) with theremove_roles
method. - For the command to work:
- The bot must have the
Manage Roles
permission on the server. - The bot must have a role superior to the roles it handles.
- The bot must have the
- It is recommended to have some control over who uses the command.
discord.py
discord-py-slash-command