I've read up on the discord.js documentation and have been trying such things that I've been reading but none of them seems to work. The main issue that I am having is that the collector is stating that it has collected nothing.
if (message.content === 'poll') {
let embedPoll = new Discord.MessageEmbed()
.setTitle('😲 DaSquad 😲')
.setColor('YELLOW')
.addField('1:', 'name')
.addField('2:', 'name2')
.addField('3:', 'name3')
.addField('4:', 'name4')
.addField('5:', 'name5')
.addField('6:', 'name6')
.addField('7:', 'name7')
.addField('8:', 'name8');
let msgEmbed = await message.channel.send({ embeds: [embedPoll] });
await msgEmbed.react('1️⃣');
await msgEmbed.react('2️⃣');
await msgEmbed.react('3️⃣');
await msgEmbed.react('4️⃣');
await msgEmbed.react('5️⃣');
await msgEmbed.react('6️⃣');
await msgEmbed.react('7️⃣');
await msgEmbed.react('8️⃣');
const filter = (reaction) =>
reaction.emoji.name === '1️⃣' ||
reaction.emoji.name === '2️⃣' ||
reaction.emoji.name === '3️⃣' ||
reaction.emoji.name === '4️⃣' ||
reaction.emoji.name === '5️⃣' ||
reaction.emoji.name === '6️⃣' ||
reaction.emoji.name === '7️⃣' ||
reaction.emoji.name === '8️⃣';
const collector = new Discord.ReactionCollector(msgEmbed, filter);
console.log(collector.collected);
}
Instead of the ReactionCollector
class, you could use either awaitReactions
or createReactionCollector
that's available on the message object you've sent (msgEmbed
).
If you're using discord.js v13, the awaitReactions
and createReactionCollector
methods accept a single parameter and the filter
is part of the options
object now. (See Changes in v13.) So, you need to update that; pass down a single object with the filter
.
Another error is that you try to read the collected reactions (collector.collected
) with a simple console.log
right after you instantiated the collector. You should instead set up event listeners and subscribe to the collect
(and probably stop
) events.
Make sure you add the GUILD_MESSAGE_REACTIONS
intents. You can read more about reaction collectors here.
And one more thing, you could create an array with all the emojis you want to react with to make your life a bit easier.
Check out the code below:
if (message.content === 'poll') {
let embedPoll = new Discord.MessageEmbed()
.setTitle('😲 DaSquad 😲')
.setColor('YELLOW')
.addField('1:', 'name')
.addField('2:', 'name2')
.addField('3:', 'name3')
.addField('4:', 'name4')
.addField('5:', 'name5')
.addField('6:', 'name6')
.addField('7:', 'name7')
.addField('8:', 'name8');
let reactions = ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣'];
let msgEmbed = await message.channel.send({ embeds: [embedPoll] });
reactions.forEach((reaction) => msgEmbed.react(reaction));
const filter = (reaction) => reactions.includes(reaction.emoji.name);
const collector = msgEmbed.createReactionCollector({ filter });
// code inside this runs every time someone reacts with those emojis
collector.on('collect', (reaction, user) => {
console.log(`Just collected a ${reaction.emoji.name} reaction from ${user.username}`);
});
}