简体   繁体   English

交互无故失败 discord.js v13

[英]interaction failed without any reason discord.js v13

I was making a simple coinflip command in my discord bot.我在我的 discord 机器人中做了一个简单的 coinflip 命令。 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我正在使用 discord.js v13 和 node.js v16

You still have to reply to the interaction using Interaction#reply() method.您仍然必须使用 Interaction#reply() 方法回复交互。 This is to acknowledge to discord that you handled the interaction.这是为了承认您处理了交互。 Something like interaction.reply("success") will probably do the jobinteraction.reply("success")这样的东西可能会完成这项工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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