I am making a discord bot in discord.js v13 and I need to make a rock, paper, scissors command and I made the following code: (I left out some parts because I couldn't post it, mainly embeds like NoResponse messages, so if something doesn't have a value, the name probably suggests what it's supposed to be!
Code:
const discord = require('discord.js');
You lost! :confused:")
.setColor(colors.COLOR);
const cancelled = new discord.MessageEmbed()
.setDescription(":x: Cancelled! You failed to respond in time!")
.setColor(colors.COLOR);
module.exports = {
name: "rps",
aliases: [],
async execute(client, message, args) {
message.channel.send({ embeds: [noResponse] }).then(msg => {
msg.react("🪨");
msg.react("✂️");
msg.react("📰");
const filter = (reaction, user) => {
return ['🪨', '✂️', '📰'].includes(reaction.emoji.name) && user.id === message.author.id;
}
const choices = ['🪨', '✂️', '📰'];
const me = choices[Math.floor(Math.random() * choices.length)];
msg.awaitReactions({ filter, max: 1, time: 20000, error: ['time'] }).then(
async (collected) => {
const reaction = collected.first();
const result = new Discord.MessageEmbed()
.setTitle("Results", `${reaction.emoji.name}`)
.addField("Your choice:", `${me}`)
.setColor(colors.COLOR)
msg.edit(result);
if ((me === "🪨" && reaction.emoji.name === "✂️") ||
(me === "✂️" && reaction.emoji.name === "📰") ||
(me === "📰" && reaction.emoji.name === "🪨")) {
message.channel.send({ embeds: [youLost] });
} else if (me === reaction.emoji.name) {
return message.channel.send({ embeds: [resultTie] });
} else {
return message.channel.send({ embeds: [youWin] });
}
})
.catch(collected => {
message.channel.send({ embeds: [cancelled] });
});
});
}
}
However, when I run the bot it sends the message, and adds the reactions, but then when the time runs out, it gives the canceled embed (it timed out) even though I reacted to the message.
I tried fixing it in multiple ways but I don't know what it is. Is it something that changed in discord.js v13?
I don't know how to fix this. Does somebody know?