'"on_raw_reaction_add" working but "on_raw_reaction_remove" not returning guild?

I coded on_eaw_reaction_add and it works just fine

    @commands.Cog.listener() 
    async def on_raw_reaction_add(self, payload):

        msgID = 754487460142121070
        user = payload.user_id
        member = payload.member

        guild_id = payload.guild_id
        guild = discord.utils.find(lambda g : g.id == guild_id, bot1.guilds)
        
        canarinho = get(member.guild.roles, name="canarinho")

        if not payload.guild_id:
            return

        if payload is not None:
            if payload.message_id == msgID:
                if str(payload.emoji) == ":canarinho:":
                    await member.add_roles(canarinho)

But when I try to remove roles it get stuck there, i think im doing something wrong pulling the specific guild

    @commands.Cog.listener() 
    async def on_raw_reaction_remove(self, payload):
    message_id = payload.message_id
    if message_id == 754487460142121070 :

        member = payload.user_id

        guild_id = payload.guild_id
        guild = discord.utils.find(lambda g: g.id == guild_id, bot.guilds)

      #here ->  role = get(member.guild.roles, name='canarinho')

        if not payload.guild_id:
            return

        if payload is not None:
            if payload.message_id == 754487460142121070:
                if str(payload.emoji) == ":canarinho:":
                    print('Working')

ERROR WHEN REMOVING REACTION

    File line 123, in on_raw_reaction_remove
        role = get(member.guild.roles, name='canarinho')
 AttributeError: 'int' object has no attribute 'guild'

EDIT I think there's something to do with payload.user_id is a user ID, not a Member object



Solution 1:[1]

The error you're getting doesn't mean that anything's wrong with the guild. It says that there's no guild in NoneType, which according to your line means member is of NoneType.

That makes sense as the payload does have a member field, but it is None for role removals as per documentation.

Use payload.user_id instead and find the user/member from there.

Solution 2:[2]

you should try something like this:

async def on_raw_reaction_add(self, payload):
    if payload.emoji.name == "?":
        reaction_role = payload.member.guild.get_role(role_id=968335072916815892)
        await payload.member.add_roles(reaction_role)

async def on_raw_reaction_remove(self, payload):
    guild = bot.get_guild(payload.guild_id)
    member = guild.get_member(payload.user_id)
    if payload.emoji.name == "?":
        reaction_role = discord.utils.get(guild.roles, name='Reaction')
        await member.remove_roles(reaction_role)

if you are not using discord.ext you should use client.get_guild instead of bot.get_guild

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lukas Schmid
Solution 2 Amirhossein Moslemi