I'm trying to make a bot where a user makes a poll and if a certain emoji that the bot has reacted with reaches a number, say 10, then it does other actions. However, that is not my issue. My issue is collecting the amount of reactions itself from that emoji.
My Code:
const embedSend = await message.channel.send({ embeds: [suggestionEmbed] }).then(async sEmbed => {
await sEmbed.react('⬆️');
await sEmbed.react('⬇️');
const filter = (reaction, user) => {
return ['⬆️', '⬇️'].includes(reaction.emoji.name) && user.id === message.author.id;
};
sEmbed.awaitReactions({ filter, max: 20, time: 50000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '⬆️') {
console.log('up');
} else if (reaction.emoji.name === '⬇️') {
console.log('down');
}
})
.catch(collected => {
console.log("didnt reach 20 reacts");
});
});
I tried using the previous method above. However, it doesn't seem to actually print up or down for every reaction after reaching 20 reacts but instead it prints nothing or just up or just down. I've tried using the line of code below to count the emojis but no luck either:
console.log(sEmbed.reactions.find(reaction => reaction.emoji.name === '⬆️').count)
Placed this inside of the .then statement with the awaitReactions right under the If-else block of code and got no output.
embedSend.reactions.cache.get('⬆️').count;
This I've placed after the embedSend and it returns me this error:
TypeError: Cannot read property 'reactions' of undefined
and if i place it within the block of code tiehr the embedSend or awaitReactions and change it to sEmbed it returns nothing.