Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda