perdu
perdu
DIAdiscord.js - Imagine an app
Created by perdu on 4/15/2024 in #djs-questions
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
6 replies