Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Discord.js How to access the message using messageReactionAdd

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading