Reputation:
So I want to add an emoji reaction to the bot's message. But idk what code to make it.
I only know the code to react to the command message.
else if(command === "guessage"){
message.channel.send({ embed: {
color: 16758465,
title: "Are you...",
description: Math.floor((Math.random() * 20) + 11) + " " + "years old?"
}
})
message.react('👍').then(() => message.react('👎'));
const filter = (reaction, user) => {
return ['👍', '👎'].includes(reaction.emoji.name) && user.id === message.author.id;
};
message.awaitReactions(filter, { max: 1, time: 60000, 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.');
});
}
Upvotes: 0
Views: 112
Reputation: 3805
You need to await the sending of the message and use it's message object.
For example:
else if (command === "guessage") {
(async () => {
let bmsg = await message.channel.send({
embed: {
color: 16758465,
title: "Are you...",
description: Math.floor((Math.random() * 20) + 11) + " " + "years old?"
}
})
await bmsg.react('👍');
await bmsg.react('👎');
const filter = (reaction, user) => {
return ['👍', '👎'].includes(reaction.emoji.name) && user.id === message.author.id;
};
bmsg.awaitReactions(filter, {
max: 1,
time: 60000,
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.');
});
})();
}
I'm using an async IIFE to allow await to be used. There are other places where await should be used, but I'll leave that up to you.
Upvotes: 0
Reputation: 6710
Handle the promise of each Message#reply()
Example Using Callbacks:
message.reply('you reacted with a thumbs up.').then(botsMessage => botsMessage.react('EMOJI-HERE'));
Example using Async/Await (Recommend for maintaining reaction order):
// Inside an async function
const botsMessage = await message.reply('you reacted with a thumbs up.');
await botMessage.react('EMOJI-1');
await botMessage.react('EMOJI-2');
await botMessage.react('EMOJI-3');
Understanding Promises - Discord.JS
Upvotes: 1