This is reaction roles button command it working but after i restart the bot it say This interaction failed how can i fix it? is it impossible? i was use simplydjs it working but i can't change the message,when user got thier roles the bot will send message and i want change it but i can't so i use collect and it not working after i restart the bot so that why i ask this question.
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 });
}
}
})
}
});
on your filter dont forget to add await i.deferUpdate()
Also your collector doesnt seem a bit using await anymore, if u wanna use async just add await too.
At collector
await i.reply("......")
on your filter
const filter = async i => {
await i.deferUpdate()
return i.customId && i.user.id === message.author.id;
}
[Edit] Also you need to end the collector after user clicked the button
await i.reply..........
await collector.stop("complete")
If you wanna continue to use that button for next interaction you dont need collector btw,
Just wrap the the condition on the interactionCreate event
client.on("interactionCreate", async (interaction) => {
if (!interaction.isButton()) return;
if(interaction.customId === "Acm") {
\\Your code here
}
})