Creating a Discord bot that adds a reaction to all messages

Hey everyone! I’m working on a fun little Discord bot project and could use some help. I want my bot to automatically add a pigeon emoji reaction to every message in the server. I’ve got some basic code set up but I’m not sure if it’s right or how to add the reaction part. Here’s what I’ve got so far:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='$', intents=discord.Intents.default())

@bot.event
async def on_ready():
    print('PigeonReactor is online!')

@bot.event
async def on_message(message):
    # This is where I think the reaction code should go
    # But I'm not sure how to do it

bot.run('YOUR_TOKEN_HERE')

Can anyone point me in the right direction for adding the emoji reaction? Thanks in advance!

I’ve implemented a similar functionality in one of my Discord bots. You’re close with your current setup. To add the reaction, modify your on_message event like this:

@bot.event
async def on_message(message):
    if message.author == bot.user:
        return
    await message.add_reaction('🐦')
    await bot.process_commands(message)

This checks if the message isn’t from the bot itself, adds the pigeon emoji reaction, and allows other commands to be processed. Remember to enable the necessary intents in your bot’s Discord Developer Portal settings. Also, consider rate limiting to avoid potential API abuse.

I’ve actually been working on a similar project recently! One thing to keep in mind is that constantly reacting to every single message can potentially hit Discord’s rate limits if your server is very active. To mitigate this, you might want to add a small delay between reactions or only react to messages in certain channels.

Here’s a snippet that worked well for me:

import asyncio

@bot.event
async def on_message(message):
    if message.author == bot.user:
        return
    try:
        await asyncio.sleep(0.5)  # Small delay to avoid rate limiting
        await message.add_reaction('🐦')
    except discord.errors.HTTPException:
        pass  # Silently handle any rate limit errors
    await bot.process_commands(message)

This approach has been pretty reliable in my experience. Just remember to adjust the delay based on your server’s activity level.

hey emma! i’ve done something similar before. you’re on the right track! in the on_message event, try adding:

await message.add_reaction(‘:bird:’)

that should make the bot react with a bird emoji to every message. let me know if u need more help!