Discord.py bot role assignment broken after updating from v1.7.3 to v2.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 fixing it by adding discord.Intents.all() and enabling intents.message_content = True but nothing changed. I’m pretty new to this stuff and can’t figure out 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, data):
        msg_id = data.message_id
        server_id = data.guild_id
        reaction = data.emoji
        
        server = self.client.get_guild(server_id)
        user = server.get_member(data.user_id)
        
        if msg_id == YOUR_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))

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

I expected that setting all intents would fix any permission issues from the version upgrade but the bot still doesn’t assign roles when people react to messages. What am I missing here?

the issue’s probably with your commands.Bot constructor. in v2.x you need to use the command_prefix parameter instead of passing the prefix as the first argument. change client = commands.Bot("?", intents=intents) to client = commands.Bot(command_prefix="?", intents=intents) and see if that fixes it.

Check if your bot still has the right permissions after upgrading. Discord.py v2.x is way stricter about permissions, and cached ones don’t always refresh properly. Try removing and re-adding your bot with a fresh OAuth2 URL that includes ‘Manage Roles’.

get_guild() and get_member() can return None if your bot doesn’t have access or there’s caching issues. Add some debug prints to check if server, user, and target_role are actually valid objects before calling add_roles(). I’ve seen cases where the code looks fine but permissions got wiped during major version updates.

Had the same problem migrating to v2.x last year. The add_cog() method changed big time in discord.py 2.0. You need await client.add_cog(RoleManager(client)) now - it’s async, not sync anymore. Do this in an on_ready event or use client.load_extension() with proper cog setup. Also check your bot has “Manage Roles” permission and make sure the bot’s role sits higher than roles you’re assigning. Permission hierarchy is strict and people miss this all the time after updates.