1

I've an issue with messageReactionAdd with floowing code :

bot.on("ready", () =>
{

// I cache the selected message declared before in message_id and channel_id 

bot.channels.cache.get(channel_id).messages.fetch(message_id).then(m => {
    console.log("Cached reaction message.");
    }).catch(e => {
    console.error("Error loading message.");
    console.error(e);
    });

})

bot.on("messageReactionAdd", (reaction, user) => {
    if(reaction.emoji.name == "" && reaction.message.id === message_id) 
    try {
        const role = reaction.message.channel.guild.roles.cache.find(role => role.name == "Membres");
        reaction.message.guild.member(user).roles.add(role);
      } catch {
        console.log('Error : can\'t add the role');
      }
});

The problem is that code works only with the owner of the cached message not with other user in the channel.

Do you know why ?

Silver
  • 13
  • 2

1 Answers1

0

If you want to create a reaction role system, you can use raw

bot.on('raw', event => {
    if (event.t === 'MESSAGE_REACTION_ADD' || event.t == "MESSAGE_REACTION_REMOVE"){
        let reaction = event.d.emoji
        let userID = enevt.d.user_id
        let messageID = event.d.message_id
        let guildID = event.d.guild_id
        let guild = bot.guilds.cache.get(guildID)
        let role = guild.roles.cache.get(role_id) //role id is defined by yourself
        let user = guild.members.cache.get(userID) //You need to enable server members intent to use that command
    }
}


and I created all of the ids and objects you can develop a reaction role system. If you did not enable server members intent, you can use:

guild.members.fetch(userID).then(user => user.roles.add(role))
Barış Çiçek
  • 341
  • 2
  • 12