Discord bot role assignment broken after updating discord.py from 1.7.3 to 2.3.2

I upgraded my Discord bot from discord.py version 1.7.3 to 2.3.2 and now the role assignment feature stopped working. I tried adding discord.Intents.all() and setting intents.message_content = True but nothing changed. I’m still learning bot development so I’m not sure what went wrong.

Here’s my current code:

import discord
from discord.ext import commands
from decouple import config

intents = discord.Intents.default()
intents.members = True
client = commands.Bot("?", intents=intents)

class RoleManager(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.Cog.listener()
    async def on_raw_reaction_add(self, event):
        msg_id = event.message_id
        server_id = event.guild_id
        reaction = event.emoji
        
        server = self.client.get_guild(server_id)
        user = server.get_member(event.user_id)
        
        if msg_id == TARGET_MESSAGE_ID:
            target_role = None
            if str(reaction) == "👤":
                target_role = server.get_role(ROLE_ID_HERE)
            elif str(reaction) == "📣":
                target_role = server.get_role(ROLE_ID_HERE)
            elif str(reaction) == "📚":
                target_role = server.get_role(ROLE_ID_HERE)
            if target_role is not None:
                await user.add_roles(target_role)
                
        elif msg_id == ANOTHER_MESSAGE_ID:
            selected_role = None
            if str(reaction) == "🎯":
                selected_role = server.get_role(ROLE_ID_HERE)
            elif str(reaction) == "🖥️":
                selected_role = server.get_role(ROLE_ID_HERE)
            elif str(reaction) == "🖌️":
                selected_role = server.get_role(ROLE_ID_HERE)
            if selected_role is not None:
                await user.add_roles(selected_role)

client.add_cog(RoleManager(client))

BOT_TOKEN = config("TOKEN")
client.run(BOT_TOKEN)

I expected that updating the intents would fix any compatibility issues between versions but the bot still doesn’t assign roles when users react to messages. What am I missing here?

Had this exact issue last month! The problem is commands.Bot constructor changed in v2.x - you can’t just pass the prefix as the first argument anymore. Change client = commands.Bot("?", intents=intents) to client = commands.Bot(command_prefix="?", intents=intents) and that should fix it.

It’s probably how you’re handling the event.emoji comparison. Discord.py 2.x changed how emojis work - str(reaction) vs unicode emojis doesn’t work reliably anymore. Switch to event.emoji.name instead of str(reaction), or just use event.emoji == '👤' directly. Also check your bot’s permissions - role assignment permissions sometimes get reset when you update the library. Had the same issue when I migrated and this fixed most of my reaction role problems.

Had the same problem when I upgraded to discord.py 2.x last year. The biggest issue was add_cog - it changed how it works. You need await client.add_cog(RoleManager(client)) now, but you’re probably calling it outside an async function. Either wrap your cog loading in a setup function or just use client.load_extension() instead. Also check that your bot has guild member intent turned on in the Discord Developer Portal - the library update might’ve messed with those settings. Usually it’s the permissions plus the cog loading change that breaks reaction roles after updates.