Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
Discord.js v13 the reaction role buttons not work after i restart the bot

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 });
                }
            }
        })
    }
});
about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

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
 }
})
about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!