Detect reactions

Hi, I'm trying to simply detect when any reaction has been added to any message. How can I do that? My end goal is to then check if it's in a certain channel before I store it temporarily, so if there's another way to do that that's also fine. I've tried using this code on Collectors just to get started understanding them from https://discordjs.guide/popular-topics/collectors.html#message-collectors but it seems like it needs to be in a command, which i'm not sure where in a command it would be since commands have a short life span and this is a more long (2 day) active thing.
// `m` is a message object that will be passed through the filter function
const collectorFilter = m => m.content.includes('discord');
const collector = interaction.channel.createMessageCollector({ filter: collectorFilter, time: 15_000 });

collector.on('collect', m => {
console.log(`Collected ${m.content}`);
});

collector.on('end', collected => {
console.log(`Collected ${collected.size} items`);
});
// `m` is a message object that will be passed through the filter function
const collectorFilter = m => m.content.includes('discord');
const collector = interaction.channel.createMessageCollector({ filter: collectorFilter, time: 15_000 });

collector.on('collect', m => {
console.log(`Collected ${m.content}`);
});

collector.on('end', collected => {
console.log(`Collected ${collected.size} items`);
});
Any help appreciated! 🙂
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
2 Replies
d.js toolkit
d.js toolkit•3mo 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! - ✅ Marked as resolved by OP
Dismissed
Dismissed•3mo ago
for reference I'm doing the same thing here, but this is to check for new messages instead of checking for new reactions:
client.on("messageCreate", async (msg) =>
{
//Check if need to start listening to messages first as to not waste resources
if (UpvoteContainer.ON == true)
{
let upvote_channel_ID = 0;
//check if message is in a channel used.
for (const x of UpvoteContainer.valid_channel_IDs)
{
if (x == msg.channelId)
{
upvote_channel_ID = x;
break;
}
}
//Only proceed is a valid channel is being used
if (upvote_channel_ID != 0)
{
if (msg.author.tag != client.user.tag)
{
UpvoteContainer.msgID.push(msg.id);
UpvoteContainer.msgAuthor.push(msg.author.displayName);
}
}
}
client.on("messageCreate", async (msg) =>
{
//Check if need to start listening to messages first as to not waste resources
if (UpvoteContainer.ON == true)
{
let upvote_channel_ID = 0;
//check if message is in a channel used.
for (const x of UpvoteContainer.valid_channel_IDs)
{
if (x == msg.channelId)
{
upvote_channel_ID = x;
break;
}
}
//Only proceed is a valid channel is being used
if (upvote_channel_ID != 0)
{
if (msg.author.tag != client.user.tag)
{
UpvoteContainer.msgID.push(msg.id);
UpvoteContainer.msgAuthor.push(msg.author.displayName);
}
}
}
I was hoping I could use client.on("messageReactionAdd" ) but apparently that only works with "cached" messages so if anyone also knows how to do that that'd be nice as I feel more confident with using client.on()
Want results from more Discord servers?
Add your server