skip to Main Content

I currently have this function in my bot that triggers every time a message is reacted to:

client.on('messageReactionAdd', (reaction, user) => {
    if(reaction.emoji.id === "1014887969808711800") {
        if (user.username !== 'IteroBetBot') {
            console.log('Fnatic');
            voterArray1.push(user.username);
        }
    } else if (reaction.emoji.id === "1065285604578959430") {
        if (user.username !== 'IteroBetBot') {
            console.log('Koi');
            voterArray2.push(user.username);
        }
    }
     else if (reaction.emoji.name === '🚫') {
         console.log('Found it');
         let finalString1 = '';
         let finalString2 = '';
         voterArray1.forEach(element => {
             finalString1 += element + " "
         });
         voterArray2.forEach(element => {
            finalString2 += element + " "
        });
        finalString1 += ' voted for Fnatic';
        finalString2 += ' voted for Koi';
        client.channels.cache.get('1077613044563202058').send(finalString1);
        client.channels.cache.get('1077613044563202058').send(finalString2);
    }
});

I need to be able to access the message that was reacted to in order to check if the stop emoji already exists on the message.

How could I access the message messageReactionAdd was called on?

2

Answers


  1. You’d use reaction.message

    Docs

    Login or Signup to reply.
  2. The first parameter, reaction has a message property. That’s the message that the reaction refers to.

    Make sure you have the correct intents and partials if you want to get reactions on older messages. If you don’t enable partial structures, your code only works on cached messages; ones posted after the bot is connected. Reacting on older messages won’t fire the messageReactionAdd event: https://stackoverflow.com/a/71950603/6126373

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search