这是反应角色按钮命令,它工作,但当我重新启动bot后,它显示此交互失败我该怎么修理它?不可能吗?我使用简单的djs它工作,但我不能改变消息,当用户得到他们的角色,机器人会发送消息,我想改变它,但我不能所以我使用收集,它不工作后,我重新启动机器人,所以为什么我问这个问题。
const Command = require("../Structures/Command.js");
const Discord = require('discord.js');
const { MessageButton } = require('discord.js');
module.exports = new Command({
name: "reactionrolebuttons",
description: "reaction role but button",
async run(message, args, client, interaction, collect) {
let embed = new Discord.MessageEmbed()
.setTitle("Ping Roles:")
.setColor("#0099ff")
.setDescription("`Click some button bellow if you want get notified!`")
const row = new Discord.MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('Acm')
.setLabel('Announcement')
.setStyle('SECONDARY')
.setEmoji("📰"),
new MessageButton()
.setCustomId('Gv')
.setLabel('Giveaways')
.setStyle('SECONDARY')
.setEmoji("🎉")
)
const m = await message.channel.send({ embeds: [embed], components: [row] });
const iFilter = i => i.user.id === message.author.id;
const collector = m.createMessageComponentCollector({ filter: iFilter, time: 60000 })
collector.on('collect', async i => {
if (i.customId === 'Acm') {
const role = message.guild.roles.cache.get("901353036759310386");
if (i.member.roles.cache?.has('901353036759310386')) {
i.member.roles.remove('901353036759310386')
i.reply({ content: `${role} was removed from you`, ephemeral: true });
} else {
i.member.roles.add('901353036759310386')
i.reply({ content: `${role} was added to you`, ephemeral: true });
}
} else if (i.customId === 'Gv') {
const role = message.guild.roles.cache.get("901370872827346975");
if (i.member.roles.cache?.has('901370872827346975')) {
i.member.roles.remove('901370872827346975')
i.reply({ content: `${role} was removed from you`, ephemeral: true });
} else {
i.member.roles.add('901370872827346975')
i.reply({ content: `${role} was added to you`, ephemeral: true });
}
}
})
}
});
不要忘记添加await . deferupdate ()
你的收集器似乎不再使用await了,如果你想使用async,也可以添加await。
在收集器
await i.reply("......")
在你的过滤器
const filter = async i => {
await i.deferUpdate()
return i.customId && i.user.id === message.author.id;
}
[编辑]此外,您需要在用户单击
按钮后结束收集器。await i.reply..........
await collector.stop("complete")
如果你想在下次交互中继续使用该按钮,你不需要收集器,顺便说一句,
只需封装interactionCreate事件的条件
client.on("interactionCreate", async (interaction) => {
if (!interaction.isButton()) return;
if(interaction.customId === "Acm") {
\Your code here
}
})