Trying to have my discord bot add roles from a reaction to a message

Question:

I’m having an issue where my bot wont give the respected role when a user reacts to the message correctly

    @client.event 
    async def on_raw_reaction_add(payload):
    
        # Get the user who added the reaction
        guild = client.get_guild(payload.guild_id)
        reacting_user = guild.get_member(payload.user_id)
    
        # Get the message object for the reaction
        channel = guild.get_channel(payload.channel_id)
        message = await channel.fetch_message(payload.message_id)
        
        # MESSAGE_ID defined in config file
        if message == MESSAGE_ID:
    
            if str(payload.emoji) == ' ':
                role = discord.utils.get(reacting_user.guild.roles, id=1056801648355324034)
                await reacting_user.add_roles(role)
    
            elif str(payload.emoji) == ' ':
                role = discord.utils.get(reacting_user.guild.roles, id=1056801755670777946)
                await reacting_user.add_roles(role)

I’ve tried using on_raw_reaction_add but I’ve have no success

Asked By: MadCappedBeef

||

Answers:

Your if condition is badly structured here. Check if payload.message_id == 1234

 if payload.message_id == 1234567:
     #stuffs

Also make sure that your intents are on.

Other issue could be the type conversation of MESSAGE_ID that you are pulling from config.ini (im guessing)
try doing:

if payload.message_id == int(MESSAGE_ID):
Answered By: puang59
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.