Reaction collector not working

Reaction collector does not seem to work for me , i am expecting to be able to collect reactions on a message or embed. Here is the slash command i created
js
const { SlashCommandBuilder } = require('discord.js');

// Create a slash command
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
// Reply with a regular message
await interaction.reply('Pong! This is a simple response.');

// Log to console when someone uses the command
console.log(`User ${interaction.user.tag} used the /ping command.`);

// Listen for an interaction with an emote
const collectorFilter = (reaction, user) => {
return reaction.emoji.name === ':thumbsup:' && user.id === interaction.user.id;
};

const collector = interaction.channel.createMessageComponentCollector({
filter: collectorFilter,
time: 15000, // 15 seconds
});

collector.on('collect', (interaction) => {
console.log(`User ${interaction.user.tag} reacted with 👍`);
});

collector.on('end', (collected, reason) => {
console.log(`Collected ${collected.size} items. Reason: ${reason}`);
});
},
};
js
const { SlashCommandBuilder } = require('discord.js');

// Create a slash command
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
// Reply with a regular message
await interaction.reply('Pong! This is a simple response.');

// Log to console when someone uses the command
console.log(`User ${interaction.user.tag} used the /ping command.`);

// Listen for an interaction with an emote
const collectorFilter = (reaction, user) => {
return reaction.emoji.name === ':thumbsup:' && user.id === interaction.user.id;
};

const collector = interaction.channel.createMessageComponentCollector({
filter: collectorFilter,
time: 15000, // 15 seconds
});

collector.on('collect', (interaction) => {
console.log(`User ${interaction.user.tag} reacted with 👍`);
});

collector.on('end', (collected, reason) => {
console.log(`Collected ${collected.size} items. Reason: ${reason}`);
});
},
};
and the results i get in console after reacting: User xxxx used the /ping command. Collected 0 items. Reason: time I have verified permissions on the developer site: Permissions are: application commands, bot, manage messages, send messages, read messages. I have many other slash commands and functions working. I have tried this with an embed and regular message. I have tried to listen for any reaction, as i thought it could be the type of thumbs up. Looking at the discord guide this should work: https://discordjs.guide/popular-topics/collectors.html#await-reactions
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
13 Replies
d.js toolkit
d.js toolkit7mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
TÆMBØØ
TÆMBØØ7mo ago
I’m seeing a message component collector in your code, but not a reaction collector
d.js docs
d.js docs7mo ago
Documentation suggestion for @maccrackalackin: :class: ReactionCollector (extends Collector) Collects reactions on messages. Will automatically stop if the message (Client#event:messageDelete messageDelete or Client#event:messageDeleteBulk messageDeleteBulk), channel (Client#event:channelDelete channelDelete), thread (Client#event:threadDelete threadDelete), or guild (Client#event:guildDelete guildDelete) is deleted.
maccrackalackin
maccrackalackin7mo ago
thankyou, i will review this and see if can get it to work I have worked through this i think, but i am getting this still after i react : User xxx used the /ping command. Collected 0 reactions. Reason: time here is the adjusted code with a reaction collector:
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
try {
console.log(`User ${interaction.user.tag} used the /ping command.`);

await interaction.reply('React with :thumbsup: within 15 seconds.');

// Get the message object from the interaction
const message = await interaction.fetchReply();

// Create a reaction collector on the message
const filter = (reaction, user) => reaction.emoji.name === ':thumbsup:' && user.id === interaction.user.id;
const collector = message.createReactionCollector({ filter, time: 15000 });

collector.on('collect', (reaction, user) => {
console.log(`User ${user.tag} reacted with 👍 `);
});

collector.on('end', (collected, reason) => {
console.log(`Collected ${collected.size} reactions. Reason: ${reason}`);
});
} catch (error) {
console.error(`Error: ${error.message}`);
}
},
};
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
try {
console.log(`User ${interaction.user.tag} used the /ping command.`);

await interaction.reply('React with :thumbsup: within 15 seconds.');

// Get the message object from the interaction
const message = await interaction.fetchReply();

// Create a reaction collector on the message
const filter = (reaction, user) => reaction.emoji.name === ':thumbsup:' && user.id === interaction.user.id;
const collector = message.createReactionCollector({ filter, time: 15000 });

collector.on('collect', (reaction, user) => {
console.log(`User ${user.tag} reacted with 👍 `);
});

collector.on('end', (collected, reason) => {
console.log(`Collected ${collected.size} reactions. Reason: ${reason}`);
});
} catch (error) {
console.error(`Error: ${error.message}`);
}
},
};
does anyone have an insight into why the collector is not working?
TÆMBØØ
TÆMBØØ7mo ago
Do you have the GuildMessageReactions intent?
maccrackalackin
maccrackalackin7mo ago
yes it is inside my client constructor, i believe that should be correct:
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents:[ GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessageReactions,
],
});
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents:[ GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessageReactions,
],
});
TÆMBØØ
TÆMBØØ7mo ago
I would try changing :thumbsup: in your collector filter to the unicode value instead 👍 I also think you might need the GuildMessages intent & Reaction partial
maccrackalackin
maccrackalackin6mo ago
I have made the code simpler by taking out the specific reaction, and included any:
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
try {
console.log(`User ${interaction.user.tag} used the /ping command.`);

await interaction.reply('React with any emoji within 15 seconds.');

// Get the message object
const message = await interaction.fetchReply();

// Reaction collector
const filter = (reaction, user) => user.id === interaction.user.id;
const collector = message.createReactionCollector({ filter, time: 15000 });

collector.on('collect', (reaction, user) => {
console.log(`User ${user.tag} reacted with ${reaction.emoji.name}`);
});

collector.on('end', (collected, reason) => {
console.log(`Collected ${collected.size} reactions. Reason: ${reason}`);
});

// Log when collector starts
console.log('Reaction collector started.');

} catch (error) {
console.error(`Error: ${error.message}`);
}
},
};
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
try {
console.log(`User ${interaction.user.tag} used the /ping command.`);

await interaction.reply('React with any emoji within 15 seconds.');

// Get the message object
const message = await interaction.fetchReply();

// Reaction collector
const filter = (reaction, user) => user.id === interaction.user.id;
const collector = message.createReactionCollector({ filter, time: 15000 });

collector.on('collect', (reaction, user) => {
console.log(`User ${user.tag} reacted with ${reaction.emoji.name}`);
});

collector.on('end', (collected, reason) => {
console.log(`Collected ${collected.size} reactions. Reason: ${reason}`);
});

// Log when collector starts
console.log('Reaction collector started.');

} catch (error) {
console.error(`Error: ${error.message}`);
}
},
};
I have given the bot Adminstrator permissions and application.command + bot command scope for testing. Added some extra console logs for testing. Add and removed the bot again : These are the console results after reacting to the message. User XXXX used the /ping command. Reaction collector started. Collected 0 reactions. Reason: time What i do notice is the 'reaction' inside the collector is declared but never used. so i am not sure if that filter/collector is correct
No description
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
maccrackalackin
maccrackalackin6mo ago
thanks for the input, i apprecciate it it alot, i changed the filter with the same results however. I did have the bot scope, i just didnt have administrator untill recently to make sure i had no permission issues. I have other slash commands working perfectly with a lot of functionality, its just a simple react collector that doesnt seem to work.
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs6mo ago
Documentation suggestion for @maccrackalackin: :event: (event) Collector#ignore Emitted whenever an element is not collected by the collector.
maccrackalackin
maccrackalackin6mo ago
Thats a good idea. i tried the ignore event before and after the end event to see if it made a difference , Alas it did not, I think i coded it correctly but it did not seem to write to console anything: User xxx used the /ping command. Reaction collector started. Collected 0 reactions. Reason: time
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
try {
console.log(`User ${interaction.user.tag} used the /ping command.`);

await interaction.reply('React with any emoji within 15 seconds.');

// Get the message object
const message = await interaction.fetchReply();

// Reaction collector
const reactFilter = (reaction, user) => user.id === interaction.user.id;
const collector = message.createReactionCollector({ filter: reactFilter, time: 15000 });

collector.on('collect', (reaction, user) => {
console.log(`User ${user.tag} reacted with ${reaction.emoji.name}`);
});

collector.on('end', (collected, reason) => {
console.log(`Collected ${collected.size} reactions. Reason: ${reason}`);
});

collector.on('ignore', (args) => {
console.log('Element ignored:', args);
});

// Log when collector starts
console.log('Reaction collector started.');

} catch (error) {
console.error(`Error: ${error.message}`);
}
},
};
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
try {
console.log(`User ${interaction.user.tag} used the /ping command.`);

await interaction.reply('React with any emoji within 15 seconds.');

// Get the message object
const message = await interaction.fetchReply();

// Reaction collector
const reactFilter = (reaction, user) => user.id === interaction.user.id;
const collector = message.createReactionCollector({ filter: reactFilter, time: 15000 });

collector.on('collect', (reaction, user) => {
console.log(`User ${user.tag} reacted with ${reaction.emoji.name}`);
});

collector.on('end', (collected, reason) => {
console.log(`Collected ${collected.size} reactions. Reason: ${reason}`);
});

collector.on('ignore', (args) => {
console.log('Element ignored:', args);
});

// Log when collector starts
console.log('Reaction collector started.');

} catch (error) {
console.error(`Error: ${error.message}`);
}
},
};
is there a working example of the reaction collector i can test, or if someone can test this code to see if it works. Otherwise i am not sure how else to troubleshoot this
Want results from more Discord servers?
Add your server