0
votes

so im making a discord bot and I have an error:

Ignoring exception in on_raw_reaction_remove Traceback (most recent call last): File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event await coro(*args, **kwargs) File "main.py", line 41, in on_raw_reaction_remove await payload.member.remove_roles(role) AttributeError: 'NoneType' object has no attribute 'remove_roles'

on_raw_reaction_remove() code:

@client.event
async def on_raw_reaction_remove(payload):
  if payload.message_id == 865402961585111111:
    if str(payload.emoji) == "✅":
      guild = client.get_guild(payload.guild_id)
      role = discord.utils.get(guild.roles, name='Announcements')
      await payload.member.remove_roles(role)

on_raw_reaction_add() code:

@client.event
async def on_raw_reaction_add(payload):
  if payload.message_id == 865402961585111111:
    if str(payload.emoji) == "✅":
      guild = client.get_guild(payload.guild_id)
      role = discord.utils.get(guild.roles, name='Announcements')
      await payload.member.add_roles(role)

The strange thing is, with on_raw_reaction_add() it returns a valid user.

1
NoneType = Something does not exist.Dominik
I know, that's the problem. payload.member returns none type even though it should return a memberkoiyaboi
Try payload.member.guild.roles instead.Dominik
but that's not the issue, the issue is that payload.member is none, and when I did what you said it told me "none does not have attribute guild"koiyaboi
Do you have Intents enabled?Dominik

1 Answers

0
votes

I changed your event a bit and added some checks to make sure everything is correct.

There were always problems with finding the role, so you need to do things a little differently.

Take a look at the following code:

@client.event
async def on_raw_reaction_remove(payload):
    guild = client.get_guild(payload.guild_id)
    print("Guild checked.")
    member = discord.utils.get(guild.members, id=payload.user_id)
    print("Member checked.")
    if payload.message_id == 865402961585111111:
        print("Got message.")
        if str(payload.emoji) == "✅":
            print("Checked for the reaction.")
            role = discord.utils.get(guild.roles, name='Announcements')
            print("Got the role.")
        else:
            role = discord.utils.get(guild.roles, name=payload.emoji)

        if role is not None:
            await member.remove_roles(role)
            print("Removed the role")

If the code is not self-explanatory, I'll be happy to add some explanations.

EDIT: After looking at the full code the problem seems to be with the Intents. You named them correctly but did not import them.

To import them you use:

client = commands.Bot(command_prefix="YourPrefix", intents=intents1)