add reaction to a reply message

console.log("Hello world!")
console.log("Hello world!")
i'm trying to add a reaction to the replying message at a slash command Code:
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName("react")
.setDescription("test reaction")
,
async execute(interaction) {
const message = await interaction.reply("choice")
message.react('šŸ‘').then(() => message.react('šŸ‘Ž'));

const collectorFilter = (reaction, user) => {
return ['šŸ‘', 'šŸ‘Ž'].includes(reaction.emoji.name) && user.id === interaction.user.id;
};

message.awaitReactions({ filter: collectorFilter, max: 1, time: 60_000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();

if (reaction.emoji.name === 'šŸ‘') {
message.reply('You reacted with a thumbs up.');
} else {
message.reply('You reacted with a thumbs down.');
}
})
.catch(collected => {
message.reply('You reacted with neither a thumbs up, nor a thumbs down.');
});
},
};
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName("react")
.setDescription("test reaction")
,
async execute(interaction) {
const message = await interaction.reply("choice")
message.react('šŸ‘').then(() => message.react('šŸ‘Ž'));

const collectorFilter = (reaction, user) => {
return ['šŸ‘', 'šŸ‘Ž'].includes(reaction.emoji.name) && user.id === interaction.user.id;
};

message.awaitReactions({ filter: collectorFilter, max: 1, time: 60_000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();

if (reaction.emoji.name === 'šŸ‘') {
message.reply('You reacted with a thumbs up.');
} else {
message.reply('You reacted with a thumbs down.');
}
})
.catch(collected => {
message.reply('You reacted with neither a thumbs up, nor a thumbs down.');
});
},
};
(the main code of the function come of this link https://discordjs.guide/popular-topics/reactions.html#awaiting-reactions) but i've got an error message
TypeError: message.react is not a function
at Object.execute (/home/runner/discordjs/commands/react.js:10:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (/home/runner/discordjs/Commands.js:30:4)
TypeError: message.react is not a function
at Object.execute (/home/runner/discordjs/commands/react.js:10:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (/home/runner/discordjs/Commands.js:30:4)
and on discord there is no reaction added by the bot thanks for helping me to understand why the bot don't react to it message
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
5 Replies
d.js toolkit
d.js toolkitā€¢9mo 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!
perdu
perduOPā€¢9mo ago
npm -v => 10.4.0 npm list discord.js => [email protected] /home/runner/discordjs ā””ā”€ā”€ [email protected]
Kapoen
Kapoenā€¢9mo ago
In order to react to a message the message needs to be fetched, so insteand of const message = await interaction.reply("choice") use const message = await interaction.reply({ content: "choice", fetchReply: true });
perdu
perduOPā€¢9mo ago
thanks but when i swap for you code i've got this error
/home/runner/discordjs/node_modules/discord.js/src/structures/Message.js:804
if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
^

Error [ChannelNotCached]: Could not find the channel where this message came from in the cache!
at Message.react (/home/runner/discordjs/node_modules/discord.js/src/structures/Message.js:804:30)
at Object.execute (/home/runner/discordjs/commands/react.js:9:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (/home/runner/discordjs/Commands.js:30:4) {
code: 'ChannelNotCached'
}
/home/runner/discordjs/node_modules/discord.js/src/structures/Message.js:804
if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
^

Error [ChannelNotCached]: Could not find the channel where this message came from in the cache!
at Message.react (/home/runner/discordjs/node_modules/discord.js/src/structures/Message.js:804:30)
at Object.execute (/home/runner/discordjs/commands/react.js:9:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (/home/runner/discordjs/Commands.js:30:4) {
code: 'ChannelNotCached'
}
and the bot as reply this message with no reactions :
No description
duck
duckā€¢9mo ago
what sort of channel is this? is this a dm channel? if so, do you have the Channel partial? if not, do you have the Guilds intent?
Want results from more Discord servers?
Add your server