A Discord role bot (auto roles and role buttons), built from blocks
Two common jobs: give a role to everyone who joins, and let members choose their own roles with a button. Both use the *Add Role* and *Remove Role* blocks, with a different trigger.
How to build it
- Auto role. Create a command with an Event trigger on Guild Member Add and add Add Role with the user set to
((member.id))and the ID of the role to give. - Role button. In a command, send a message with Send Message (or Respond with Message) that carries a button with a custom ID such as
role_news. - Create an Event trigger on
interactionCreatewith the custom ID filterrole_news. Add Add Role with the user set to((interaction.userId))and the role ID, then Respond with Message with a private reply to confirm. - Add a second button and flow with Remove Role if members should be able to leave the role.
Blocks you will use
Block names are the ones of the app; each links to its entry in the dictionary.
- Add Role — Gives a role to a member.
- Remove Role — Takes a role away from a member.
- Send Message — Posts the message that carries the role buttons.
- Respond with Message — Confirms to the member who clicked, privately if you tick the option.
What to know
- The bot needs the Manage Roles permission, and its role must sit above every role it gives (Discord rule).
- A button does one action. For a toggle, make two buttons (add and remove) or build the check yourself with an IF / ELSE Block.
- Join events need the Server Members Intent, as in the welcome bot.