meadow
meadow
DIAdiscord.js - Imagine an app
Created by meadow on 10/21/2023 in #djs-questions
what permission is needed to listen for MessageReactionAdd in user's DMs?
I am using the boilerplate code from the example of "listening for a reaction on an old message" from the tutorial docs. the MessageReactionAdd event is only firing if my bot sends a message to a guild and the user reacts there. I would like this bot to work in DMs as well. what permission to I need for MessageReactionAdd to fire in DMs? I am using v14.13.0, here is my code: in my main file:
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction, Partials.User],
});
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction, Partials.User],
});
in my event file file:
export let name = Events.MessageReactionAdd

export async function execute (reaction, user) {

// When a reaction is received, check if the structure is partial
if (reaction.partial) {
// If the message this reaction belongs to was removed, the fetching might result in an API error which should be handled
try {
await reaction.fetch();
} catch (error) {
console.error('Something went wrong when fetching the message:', error);
// Return as `reaction.message.author` may be undefined/null
return;
}
}

// Now the message has been cached and is fully available
console.log(`${reaction.message.author}'s message "${reaction.message.content}" gained a reaction!`);
// The reaction is now also fully available and the properties will be reflected accurately:
console.log(`${reaction.count} user(s) have given the same reaction to this message!`);

}
export let name = Events.MessageReactionAdd

export async function execute (reaction, user) {

// When a reaction is received, check if the structure is partial
if (reaction.partial) {
// If the message this reaction belongs to was removed, the fetching might result in an API error which should be handled
try {
await reaction.fetch();
} catch (error) {
console.error('Something went wrong when fetching the message:', error);
// Return as `reaction.message.author` may be undefined/null
return;
}
}

// Now the message has been cached and is fully available
console.log(`${reaction.message.author}'s message "${reaction.message.content}" gained a reaction!`);
// The reaction is now also fully available and the properties will be reflected accurately:
console.log(`${reaction.count} user(s) have given the same reaction to this message!`);

}
thank you
5 replies