Reaction Roles Discord Bot

Minahil Faisal
 
import os
import discord
from discord.ext import commands

# Environment variables
BOT_TOKEN = os.environ['DISCORD_BOT_TOKEN']
GUILD_ID = int(os.environ['GUILD_ID'])
MESSAGE_ID = int(os.environ['MESSAGE_ID'])

# Reaction-role mapping
REACTION_ROLE_MAP = {
    '🔴': 'team red',
    '🔵': 'team blue',
    # TODO: Add more reaction-role pairs as needed
}

intents = discord.Intents.default()
intents.members = True
intents.reactions = True

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event

About this template

The Discord bot can manage multiple user roles based on reactions to a specific message. The reaction-role mapping is included directly in the code for easy editing by the builder.

Introduction to the Reaction Roles Discord Bot Template

Welcome to the Reaction Roles Discord Bot Template! This template allows you to create a Discord bot that can automatically manage user roles based on reactions to a specific message. This is particularly useful for community servers where you want to assign roles without manual intervention. The bot uses emoji reactions as triggers to assign or remove roles from users in your Discord server.

Clicking Start with this Template

To begin using this template, simply click on the "Start with this Template" button. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code manually.

Initial setup: Adding Environment Secrets

Before you can test and deploy your bot, you need to set up a few environment secrets within the Lazy Builder. These secrets include your Discord bot token, the ID of your guild (server), and the ID of the message you want to use for reaction roles.

  • DISCORD_BOT_TOKEN: This is the token for your Discord bot. You can obtain it from the Discord Developer Portal after creating your bot.
  • GUILD_ID: The numerical ID of your Discord server. You can find this by enabling Developer Mode in Discord, right-clicking on your server name, and selecting "Copy ID".
  • MESSAGE_ID: The numerical ID of the message that will be used for assigning roles. Obtain this by right-clicking on the message and selecting "Copy ID" (Developer Mode required).

Enter these values in the Environment Secrets tab within the Lazy Builder.

Test: Pressing the Test Button

Once you have set up the environment secrets, press the "Test" button to begin the deployment of your app. The Lazy CLI will handle the deployment process, and you won't need to worry about installing libraries or setting up your environment.

Using the App

After deployment, your Discord bot will be live and ready to manage roles based on reactions. Here's how it works:

  • When a user reacts to the specified message with an emoji that is mapped to a role in the REACTION_ROLE_MAP dictionary, the bot will automatically assign that role to the user.
  • If a user removes their reaction, the bot will remove the corresponding role from that user.

Make sure the bot has the necessary permissions to manage roles in your Discord server and that the roles you want to assign are correctly named in the REACTION_ROLE_MAP dictionary within the code.

Integrating the App

To integrate this bot into your Discord server, you need to invite the bot to your server using the OAuth2 URL generated in the Discord Developer Portal. Ensure you grant the bot the 'Manage Roles' permission and any other permissions it may require to function correctly.

After inviting the bot to your server, make sure to place the bot's role above the roles it will manage in the server's role hierarchy. This is necessary for the bot to have the ability to assign and remove roles from users.

With the bot set up and integrated into your server, you can now enjoy automated role management based on user reactions. This will make your server more interactive and engaging for your community.

If you need to make changes to the reaction-role mappings or add new ones, you can do so directly in the Lazy Builder interface by updating the REACTION_ROLE_MAP dictionary in the code.

Enjoy your new Reaction Roles Discord Bot!

Category
Technology
Last published
June 15, 2024

More templates like this

Discord Ticketbot Template

A simple Discord Ticketbot for your Discord Support Department. This Template and Bot is fully customizable but already build so that you can use it right away. You need a bot token from https://discord.com/developers/applications for your bot to work. These are the steps needed to get your token: "1. 🌐 Go to the Discord Developer Portal. 🌐\n" + "2. 🆕 Create a new application and navigate to the 'Bot' section. 🤖\n" + "3. 📋 Under the 'TOKEN' section, click 'Reset Token' to get your Discord bot token and confirm by clicking 'Yes, do it'. 🔑\n" + "4. 🤖 If your bot will have any ability to read/reply to messages, then under the 'BOT' section, enable the slider titled 'Message Content Intent' ✅" + "5. 🔐 Set the 'DISCORD_BOT_TOKEN' in the Env Secrets tab with your bot token from step 3. 🔐\n" + "For bot permissions, it's recommended to start with basic permissions and adjust as needed for your app's functionality.🚀") If you encounter any bugs, please tell Lazy to fix them and report them on the Official Lazy AI Discord to @D4vidG4merLP. Credits: @meow - the Discord bot slash command template @mrlazy.notlazy - supporting me And the Biggest Thank you. You for using this template ❤️

Discord

Discord bot using slash commands in python

Just a cute /ping bot

Discord
Python
Flask

Basic Discord Bot

A Discord bot that does nothing (excellent starting point). Think of it as the plain paper of Discord bots. It does nothing at all and you can turn it into whatever you want. All you need to set is a Discord bot token from your Discord developer portal and boom! You're done.

Discord
Python
Home
/
Reaction Roles Discord Bot