im not very new in discord.py but i dont know the rewrite version well and heroku forces me to use it.
Im trying to add a role if someone reacts with the on_raw_reaction_add event. My bot has all scopes expect from the webhook and guilds.join
Somehow whenever someone reacts this error comes:
discord.errors.NotFound: 404 Not Found (error code: 10011): Unknown Role
here is the code:
@client.event async def on_raw_reaction_add(payload: discord.RawReactionActionEvent): channel = await client.fetch_channel(payload.channel_id) message = await channel.fetch_message(payload.message_id) if message.id == 876059709889720331: if payload.emoji.name == u'U0001F52B': guild = await client.fetch_guild(payload.guild_id) if guild is not None: member = (payload.user_id) print(member) member = discord.utils.get(client.get_all_members(), id=member) role1 = get(guild.roles, name="R6S") print(role1) await member.add_roles(role1)
i noticed that when i print (role1) it even says “R6S” but i dont know if this is important
The issue lies here
member = discord.utils.get(client.get_all_members(), id=member)
This will check every
discord.Member instance of every guild your bot can see, including ones in other guilds, to find one which has the requested id. That’s why you can’t add this role to the user – you got the
discord.Member instance of another guild in which that role doesn’t exist. Remember that
utils.get returns the first match it finds (docs) in case there are multiple, and as your only specification was the
id this will have multiple matches.
If you want a user’s instance from a specific guild, you can use
Guild.get_member(), assuming you already have the guild (which you do as you get it a few lines higher up).
member = guild.get_member(member_id_goes_here)