1

I've been on my discord bot for several days because I encountered a problem ...

I wanted to add the possibility of having a role following a reaction.

But it doesn't work as soon as I add the line to add the role, if I remove it it works fine.

code :

bot.on("messageReactionAdd", (reaction, member) => {

    if(reaction.message.id === "894623823855493171"){

        member.roles.add('892423129345978438');
        reaction.message.channel.send(`Tu as réagi : ✅ ${member}`);

    }
       
})
I_love_vegetables
  • 1,575
  • 5
  • 12
  • 26
Cris
  • 11
  • 1

1 Answers1

0

member is actually a User. The better way to do this is to get the GuildMember from the Guild. You can use GuildMemberManager.resolve

bot.on("messageReactionAdd", (reaction, user) => {
  if(reaction.message.id === "894623823855493171"){
    const member = reaction.guild.members.resolve(user)
    member.roles.add('892423129345978438');
    reaction.message.channel.send(`Tu as réagi : ✅ ${member}`);
  }
})
MrMythical
  • 8,908
  • 2
  • 17
  • 45
  • See [this question](https://stackoverflow.com/questions/63979076/what-is-the-difference-between-a-user-and-a-guildmember-in-discord-js) for more info – MrMythical Oct 05 '21 at 16:22