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β€’2mo 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β€’2mo ago
might need the partials?
SowerofSystems
SowerofSystemsβ€’2mo 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
SowerofSystemsβ€’2mo ago
what do you mean?
Benluka.dev
Benluka.devβ€’2mo ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Benluka.dev
Benluka.devβ€’2mo ago
you need channel partial to get messages so would make sense to have them as well i think.
SowerofSystems
SowerofSystemsβ€’2mo 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β€’2mo ago
get dm intent asw
SowerofSystems
SowerofSystemsβ€’2mo 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β€’2mo ago
Guilds is one you should ideally always enable Seen you also have GuildMessages, just keep it
SowerofSystems
SowerofSystemsβ€’5w 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
SowerofSystemsβ€’4w ago
I still can't figure out why it won't respond
Want results from more Discord servers?
Add your server