discord.py/nextcord.py Reaction role with on_raw_reaction_add not working

Question:

I´ve been a long time trying to figure out why this isn´t working, the part that doesn´t work is where I get the role, but I can´t figure out why.

Does anyone know? :c

@client.event
async def on_raw_reaction_add(payload):
  message_id = 999984925216358470

  if message_id == payload.message_id:
    user = payload.member
    guild_user = user.guild
    emoji = payload.emoji.name


    if emoji == "<:hi:999730650087165993>":
      role = nextcord.utils.get(guild_user.guild.roles, name="the role")
      print(role)
      await user.add_roles(role)

  else:
    print("Not a reaction roles message")
Asked By: Komrade FMX

||

Answers:

I’m not familiar with this library, but looking at the documentation tells me that the nextcord.utils.get-function does the following:

A helper that returns the first element in the iterable that meets all the traits passed in attrs

If nothing is found that matches the attributes passed, then None is returned.

I suppose, that there is no element in the iterable that meets the trait name="the role". There could be many reasons for this, maybe you can find out if you take a look at the iterable guild_user.guild.roles by printing that, or better yet using a debugger.

Answered By: MangoNrFive