Reputation: 73
I'm using the discord.py library to create a bot for my Discord server. At the moment I'm trying to handle what happens when a user removes their reaction from a message. I've updated Discord to the latest version, allowed intents both using the Developer Portal and through code like so:
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=('$', '?'), intents=intents)
Here's the code for the on_raw_reaction_remove function:
channel = 867854256647176252
message = 867855236861132860
if payload.channel_id == channel and payload.message_id == message:
guild = bot.get_guild(payload.guild_id)
member = guild.get_member(payload.user_id)
emoji = payload.emoji
global channels
channels = str(channels)
channels = channels.split()
if str(emoji.name) == '🙂' :
role = discord.utils.get(guild.roles, name='Offtopic')
for index in range(len(channels) - 1, -1, -1):
if channels[index] == 'Offtopic':
channels.pop(index)
await payload.member.remove_roles(role)
And the error it yields once the reaction is removed:
Ignoring exception in on_raw_reaction_remove
Traceback (most recent call last):
File "/home/meri/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "bot.py", line 420, in on_raw_reaction_remove
await payload.member.remove_roles(role)
AttributeError: 'NoneType' object has no attribute 'remove_roles'
None of the answers to similar problems managed to help with the situation, any help is appreciated.
Upvotes: 1
Views: 115
Reputation: 69
NoneType means that the value you're accessing (payload.member
) is set to None, and therefore has no remove_roles()
function. You defined member above as its own standalone variable, so did you intend to do member.remove_roles()
instead?
Upvotes: 1