Jared Singleton
Jared Singleton

Reputation: 1

Creating a Discord Role Bot, goes online fine, but won't actually update the roles

I am currently programming a rolebot for a small community discord server as a means to learn python 3 and the Discord library as a whole. I've mucked around all over the internet trying other solutions but I am clearly missing something. Was hoping for some guidance or idea as to what is wrong because it's not returning any errors.

@client.event
async def on_ready():
  channel = client.get_channel(<ChannelID>)  #set channel to #rules
  if isinstance(channel, discord.TextChannel):
    text = "Please read the #rules and react for verification."
    emoji = await channel.send(text)
    await emoji.add_reaction('✅')

#When reaction
    @client.event
    async def on_reaction_add(reaction, author):
      channel = client.get_channel(<ChannelId>)  #Update channel as redundancy
      if reaction.message.channel is not None and channel:
          return
      if reaction.emoji == "✅":
        author = reaction.author
        role = await reaction.author.guild.get_role(<RoleID>)
        await author.add_roles(role)  #Checks for correct reaction and adds role
        reaction.message.delete()

I've tried importing extra libraries like typing for extra features, I've tried async On_Reaction, On_Ready, and even On_Message. I do have the emojis library in case that was the issue. The role for the bot is higher than the role it's trying to assign as well, the bot has moderator privileges, guild members privileges, and all of the permissions that could even remotely be perceived as helpful for this in my head which is:

Read Message History Create Expressions Create Reactions Moderate Members Manage Roles Create Messages

I've also tried user.guild.roles and author.guild.roles for assignment.

Upvotes: 0

Views: 44

Answers (1)

There are some things wrong in your snippet. First would be that on_reaction_add event is defined inside on_ready event, that may not work as expected as it is not supported. Second, in the documentation we have the discord.on_reaction_add(reaction, user) whit has the parameters class discord.Reaction and (Union[discord.Mmeber, discord.User]. You are trying to get this:

await reaction.author.guild.get_role(<RoleID>)

https://discordpy.readthedocs.io/en/stable/api.html#discord.Reaction from here the correct way to do it is

await reaction.message.guild.get_role(<RoleID>)

then we have this:

author = reaction.author

you already have the author so there should be no reason to try to take it different. The event returns the reaction and the user, where user is the the person who reacted.

Check the documentatiion here: https://discordpy.readthedocs.io/en/stable/api.html search for discord.on_reaction_add

Upvotes: 1

Related Questions