Reaction Collector not collecting reactions in DMs

discordjs 14.12.1
// Create a reaction collector
const filter = (reaction, user) => {
console.log(`Reaction: ${reaction.emoji.name}, User: ${user.tag}`);
return ['πŸ‘', 'πŸ‘Ž'].includes(reaction.emoji.name) && !user.bot;
};

const collector = message.createReactionCollector({ filter, time: 60000 });

console.log('Collector created:', collector);

collector.on('collect', async (reaction, user) => {
console.log(`Collected ${reaction.emoji.name} from ${user.tag}`);

try {
// Check if the reaction is on an invitation message
const memberRecord = await Database.CoffeeChat.findOne({ where: { MemberId: user.id, InvitationMessageId: reaction.message.id } });
if (memberRecord && memberRecord.OptedIn) {
let response;
if (reaction.emoji.name === 'πŸ‘') {
response = true;
} else if (reaction.emoji.name === 'πŸ‘Ž') {
response = false;
}

// Update the database with the user's response
await Database.CoffeeChat.update(
{ OptedIn: response },
{ where: { InvitationMessageId: reaction.message.id } }
);
// Create a reaction collector
const filter = (reaction, user) => {
console.log(`Reaction: ${reaction.emoji.name}, User: ${user.tag}`);
return ['πŸ‘', 'πŸ‘Ž'].includes(reaction.emoji.name) && !user.bot;
};

const collector = message.createReactionCollector({ filter, time: 60000 });

console.log('Collector created:', collector);

collector.on('collect', async (reaction, user) => {
console.log(`Collected ${reaction.emoji.name} from ${user.tag}`);

try {
// Check if the reaction is on an invitation message
const memberRecord = await Database.CoffeeChat.findOne({ where: { MemberId: user.id, InvitationMessageId: reaction.message.id } });
if (memberRecord && memberRecord.OptedIn) {
let response;
if (reaction.emoji.name === 'πŸ‘') {
response = true;
} else if (reaction.emoji.name === 'πŸ‘Ž') {
response = false;
}

// Update the database with the user's response
await Database.CoffeeChat.update(
{ OptedIn: response },
{ where: { InvitationMessageId: reaction.message.id } }
);
24 Replies
d.js toolkit
d.js toolkitβ€’4mo 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!
Benluka.dev
Benluka.devβ€’4mo ago
might need the partials?
SowerofSystems
SowerofSystemsOPβ€’4mo ago
// Check if the reaction is in a DM
if (!reaction.message.guild) {
// Send a confirmation message to the user in DM
if (response) {
await user.send('Thank you for opting in for this week\'s coffee chat!');
} else {
await user.send('You have opted out of this week\'s coffee chat.');
}
} else {
// Send a confirmation message to the user in the guild
const member = await reaction.message.guild.members.fetch(user.id);
if (response) {
await member.send('Thank you for opting in for this week\'s coffee chat!');
} else {
await member.send('You have opted out of this week\'s coffee chat.');
}
}
} else {
console.log(`No member record found for user: ${user.tag} with message ID: ${reaction.message.id}`);
}
} catch (error) {
console.error('Error handling reaction:', error);
}
});

collector.on('end', collected => {
console.log(`Collected ${collected.size} reactions`);
});
}
// Check if the reaction is in a DM
if (!reaction.message.guild) {
// Send a confirmation message to the user in DM
if (response) {
await user.send('Thank you for opting in for this week\'s coffee chat!');
} else {
await user.send('You have opted out of this week\'s coffee chat.');
}
} else {
// Send a confirmation message to the user in the guild
const member = await reaction.message.guild.members.fetch(user.id);
if (response) {
await member.send('Thank you for opting in for this week\'s coffee chat!');
} else {
await member.send('You have opted out of this week\'s coffee chat.');
}
}
} else {
console.log(`No member record found for user: ${user.tag} with message ID: ${reaction.message.id}`);
}
} catch (error) {
console.error('Error handling reaction:', error);
}
});

collector.on('end', collected => {
console.log(`Collected ${collected.size} reactions`);
});
}
SowerofSystems
SowerofSystemsOPβ€’4mo ago
what do you mean?
Benluka.dev
Benluka.devβ€’4mo ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Benluka.dev
Benluka.devβ€’4mo ago
you need channel partial to get messages so would make sense to have them as well i think.
SowerofSystems
SowerofSystemsOPβ€’4mo ago
Is this what you're saying?
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const { Database } = require('djsbotbuilder');

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction, Partials.User]
});
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const { Database } = require('djsbotbuilder');

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction, Partials.User]
});
Benluka.dev
Benluka.devβ€’4mo ago
get dm intent asw
SowerofSystems
SowerofSystemsOPβ€’4mo ago
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction, Partials.User]
});
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction, Partials.User]
});
I guess I don't really need guild intents, eh?
treble/luna
treble/lunaβ€’4mo ago
Guilds is one you should ideally always enable Seen you also have GuildMessages, just keep it
SowerofSystems
SowerofSystemsOPβ€’4mo ago
Adding that didn't solve the issue. It's still not recognizing when I react to the message My bot DMs the user, and I need to capture their reaction so that I can record whether they are interested this week.
Message sent: <ref *1> Message {
channelId: '1190269311462412358',
guildId: null,
id: '1273010475734667338',
createdTimestamp: 1723579748806,
type: 0,
system: false,
content: `Would you like to participate in this week's coffee chat? React with πŸ‘ for "yes" or πŸ‘Ž for "no".`,
author: ClientUser {
id: '1188092579821137920',
bot: true,
system: false,
flags: UserFlagsBitField { bitfield: 0 },
username: 'Blenda_dev',
globalName: null,
discriminator: '4331',
avatar: 'bcc87f22fdf38cd4510c740dc45094bd',
banner: null,
accentColor: null,
avatarDecoration: null,
verified: true,
mfaEnabled: true
},
pinned: false,
tts: false,
nonce: null,
embeds: [],
components: [],
attachments: Collection(0) [Map] {},
stickers: Collection(0) [Map] {},
position: null,
roleSubscriptionData: null,
resolved: null,
editedTimestamp: null,
reactions: ReactionManager { message: [Circular *1] },
mentions: MessageMentions {
everyone: false,
users: Collection(0) [Map] {},
roles: Collection(0) [Map] {},
_members: null,
_channels: null,
_parsedUsers: null,
crosspostedChannels: Collection(0) [Map] {},
repliedUser: null
},
webhookId: null,
groupActivityApplication: null,
applicationId: null,
activity: null,
flags: MessageFlagsBitField { bitfield: 0 },
reference: null,
interaction: null,
poll: null
}
Message sent: <ref *1> Message {
channelId: '1190269311462412358',
guildId: null,
id: '1273010475734667338',
createdTimestamp: 1723579748806,
type: 0,
system: false,
content: `Would you like to participate in this week's coffee chat? React with πŸ‘ for "yes" or πŸ‘Ž for "no".`,
author: ClientUser {
id: '1188092579821137920',
bot: true,
system: false,
flags: UserFlagsBitField { bitfield: 0 },
username: 'Blenda_dev',
globalName: null,
discriminator: '4331',
avatar: 'bcc87f22fdf38cd4510c740dc45094bd',
banner: null,
accentColor: null,
avatarDecoration: null,
verified: true,
mfaEnabled: true
},
pinned: false,
tts: false,
nonce: null,
embeds: [],
components: [],
attachments: Collection(0) [Map] {},
stickers: Collection(0) [Map] {},
position: null,
roleSubscriptionData: null,
resolved: null,
editedTimestamp: null,
reactions: ReactionManager { message: [Circular *1] },
mentions: MessageMentions {
everyone: false,
users: Collection(0) [Map] {},
roles: Collection(0) [Map] {},
_members: null,
_channels: null,
_parsedUsers: null,
crosspostedChannels: Collection(0) [Map] {},
repliedUser: null
},
webhookId: null,
groupActivityApplication: null,
applicationId: null,
activity: null,
flags: MessageFlagsBitField { bitfield: 0 },
reference: null,
interaction: null,
poll: null
}
I see, the message is defined here:
const message = await member.send('Would you like to participate in this week\'s coffee chat? React with πŸ‘ for "yes" or πŸ‘Ž for "no".');
const message = await member.send('Would you like to participate in this week\'s coffee chat? React with πŸ‘ for "yes" or πŸ‘Ž for "no".');
Here is the full code before the collector:
NΝ₯eΝ£oΝ«ΚΈα΅’α΅˜Κ³ α΅ƒα΅˜βΏα΅—ΚΈ
@SowerofSystems, I think the issue might be related to your filter. You're checking if the user's reaction matches one of two specific emojis by comparing the emoji.name property to an array of emoji characters. However, the emoji.name property isn't actually the Unicode character (that you have specified in the array) but rather the emojis literal name (:thumbsup: in this case) therefor doesn't match, causing the function to return false. Instead of using emoji.name you should be able to use emoji.toString() (I think) or just have the emoji's literal name in the array instead of the Unicode characters. Hope that makes sense. ^ Incorrect Just thought this to be the case from previous programming knowledge. Apologies for the incorrect response πŸ™.
SowerofSystems
SowerofSystemsOPβ€’3mo ago
I still can't figure out why it won't respond
πŸ€– RoboticRobot πŸ€–
it would be ideal if you updated the version to newest. Perhaps there is a bug in that version?
SowerofSystems
SowerofSystemsOPβ€’3mo ago
I have now updated to 14.15.3, it still isn't responding. I have made a few adjustments to the script while trying to fix this issue, so for reference here is the current code:
duck
duckβ€’3mo ago
could you clarify how this function is being called? you appear to have a Client defined at the top of this file, but you're also exporting a function that receives a client as a param? is it possible this client where you have the correct intents/partials isn't actually the client that's logged in?
SowerofSystems
SowerofSystemsOPβ€’3mo ago
The function is intended to be run automatically on a weekly schedule, but for testing purposes I am running it manually with a slash command send-invitations
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const coffeeChatScheduler = require('../../tasks/coffeeChatScheduler');

module.exports = {
data: new SlashCommandBuilder()
.setName('send-invitations')
.setDescription('Manually send out coffee chat invitations to opted-in members.')
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers),
async execute(interaction) {
const client = interaction.client;

try {
await coffeeChatScheduler.execute(client);
await interaction.reply('Coffee chat invitations have been sent out successfully.');
} catch (error) {
console.error('Failed to send coffee chat invitations:', error);
await interaction.reply('There was an error sending out coffee chat invitations.');
}
},
};
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const coffeeChatScheduler = require('../../tasks/coffeeChatScheduler');

module.exports = {
data: new SlashCommandBuilder()
.setName('send-invitations')
.setDescription('Manually send out coffee chat invitations to opted-in members.')
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers),
async execute(interaction) {
const client = interaction.client;

try {
await coffeeChatScheduler.execute(client);
await interaction.reply('Coffee chat invitations have been sent out successfully.');
} catch (error) {
console.error('Failed to send coffee chat invitations:', error);
await interaction.reply('There was an error sending out coffee chat invitations.');
}
},
};
I just realized that the client definition wasn't doing anything. I have removed it from the beginning of coffeeChatScheduler. My issue persists though.
duck
duckβ€’3mo ago
could you show your actual client definition then? have you ensured you have the proper intents/partials there?
SowerofSystems
SowerofSystemsOPβ€’3mo ago
I define the client in my index.js here:
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const { Init } = require('djsbotbuilder');

Init.database();

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessageReactions
],
partials: [
Partials.Message,
Partials.Channel,
Partials.Reaction
]
});

Init.runBot({ client });
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const { Init } = require('djsbotbuilder');

Init.database();

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessageReactions
],
partials: [
Partials.Message,
Partials.Channel,
Partials.Reaction
]
});

Init.runBot({ client });
duck
duckβ€’3mo ago
this djsbotbuilder package (which I notice is yours) does not seem to take a client as an option of runBot it does define its own Client internally, so you should take a look at that client definition
SowerofSystems
SowerofSystemsOPβ€’3mo ago
Ah yes, I have recently changed djsbotbuilder to take client. I have not yet published that change, but I am using a linked version of djsbotbuilder for testing. This is the current runBot function:
static async runBot(options = {}) {
const config = this.getConfig();
const token = options.token || config.TOKEN;
const client = options.client;

if (!client) {
throw new Error('Client must be provided in options.');
}

client.commands = this.getCommands();

await this.deployCommands(options);

this.loadEvents({ client });

this.loadTasks({ client });

client.login(token).then(() => {
console.log('Bot is online.');
}).catch((error) => {
console.error('Failed to log in:', error);
});
}
static async runBot(options = {}) {
const config = this.getConfig();
const token = options.token || config.TOKEN;
const client = options.client;

if (!client) {
throw new Error('Client must be provided in options.');
}

client.commands = this.getCommands();

await this.deployCommands(options);

this.loadEvents({ client });

this.loadTasks({ client });

client.login(token).then(() => {
console.log('Bot is online.');
}).catch((error) => {
console.error('Failed to log in:', error);
});
}
I don't believe I have made any other changes to djsbotbuilder since my last publish I still haven't been able to figure this out
Want results from more Discord servers?
Add your server