My goal here is to count the reactions but when i react on the reaction the bot doesn't count and if two people react i wont get the two reactions.
collector.on('end', (collected) => {
let i = 0;
const collectedembed = new Discord.MessageEmbed();
collected.forEach((value) => {
i++;
collectedembed.setTitle(question);
if (i === 1) {
collectedembed.addField('1st option', value.content);
} else if (i === 2) {
collectedembed.addField('2nd option', value.content);
}
});
message.channel.send({ embeds: [collectedembed] }).then((poll) => {
poll.react('1️⃣');
poll.react('2️⃣');
const filter2 = (reaction, user) => {
return ['1️⃣', '2️⃣'].includes(reaction.emoji.name) && user.id === message.author.id;
};
const collector2 = poll.createReactionCollector({ filter: filter2, time: 5000 });
collector2.on('end', (collected) => {
poll.channel.send(
`reacted with 1️⃣ ${poll.reactions.cache.get('1️⃣').count} users \n reacted with 2️⃣${
poll.reactions.cache.get('2️⃣').count
} users`,
);
});
});
});
here is an image example of my issue:
You should count the amount of each of the reactions received by using the <Collection>
parameter of the <ReactionCollector>.on('end', ...)
method's callback function:
collector2.on('end', collected => {
poll.channel.send(collected.map(reaction => `${reaction.emoji} » ${reaction.count} Users`).join('\n'));
});