简体   繁体   中英

interaction failed without any reason discord.js v13

I was making a simple coinflip command in my discord bot. It is working but makes an "Interaction Failed" event without reason. It edits the embed and changes things it should change. and it deletes the message without any problem.

My Code:

const randomResult = Math.floor(Math.random() * 2) == 0 ? "Heads" : "Tails";

const embed = new MessageEmbed()
.setTitle("Coin Flip")
.setColor("YELLOW")
.setDescription(` > ${randomResult}`)
.setFooter({
text: `Requested by ${message.author.username}`,
iconURL: message.author.displayAvatarURL(),
});

const row = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId("again")
.setLabel("Throw Again")
.setEmoji("🔁")
.setStyle("PRIMARY"),

new MessageButton()
.setCustomId("delete")
.setLabel("Delete")
.setEmoji("♻")
.setStyle("DANGER")
);
message.channel.send({ embeds: [embed], components: [row] }).then(msg => {
global.msg = msg;
})
const iFilter = (i) => i.user.id === message.author.id;
const collector = message.channel.createMessageComponentCollector({
filter: iFilter,
time: 30000,
});
collector.on("collect", async (i) => {
if (i.customId === "again") {
const randomResult =
Math.floor(Math.random() * 2) == 0 ? "Heads" : "Tails";
const newEmbed = new MessageEmbed()
.setTitle("Coin Flip")
.setColor("YELLOW")
.setDescription(` > ${randomResult}`)
.setFooter({
text: `Requested by ${message.author.username}`,
iconURL: message.author.displayAvatarURL(),
});
const row = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId("again")
.setLabel("Throw Again")
.setEmoji("🔁")
.setStyle("PRIMARY"),
new MessageButton()
.setCustomId("delete")
.setLabel("Delete")
.setEmoji("♻")
.setStyle("DANGER")
);
msg.edit({ embeds: [newEmbed], components: [row] });
}
if (i.customId === "delete") {
msg.delete();
}
})
collector.on("end", async (i) => {
const newEmbed2 = new MessageEmbed()
.setTitle("Coin Flip")
.setColor("YELLOW")
.setDescription(` > ${randomResult}`)
.setFooter({
text: `Requested by ${message.author.username}`,
iconURL: message.author.displayAvatarURL(),
});
const row = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId("ended")
.setLabel("Coin Flip Ended")
.setEmoji("❎")
.setStyle("DANGER")
.setDisabled(true),
);
msg.edit({embed: [newEmbed2], components: [row]})
})

Note: I am not getting any errors. I am using discord.js v13 and node.js v16

You still have to reply to the interaction using Interaction#reply() method. This is to acknowledge to discord that you handled the interaction. Something like interaction.reply("success") will probably do the job

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM