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

140
Visualizações
Update discord-buttons on InteractionCreate

In Discord MessageButtons, MessageActionRow

I'm having a MessageActionRow() running into a message embed, added buttons addComponents to that message, on createInteraction when a "PauseButton" is clicked, the button replaces with another button called "ResumeButton", same same.

const PauseButton = new MessageButton()
.setCustomId('PauseButton')
.setLabel('Pause')
.setStyle('SUCCESS')
.setEmoji('⏸️');

const ResumeButton = new MessageButton()
.setCustomId('ResumeButton')
.setLabel('Resume')
.setStyle('SUCCESS')
.setEmoji('▶️');

//SkipButton, StopButton

const Buttons = new MessageActionRow().addComponents(PauseButton, SkipButton, StopButton);
const ResumeButtons = new MessageActionRow().addComponents(ResumeButton, SkipButton, StopButton);

const sendMessage = await QueueChannel.send({ embeds: [sendMessageEmbed], components: [Buttons] });

this.client.on('interactionCreate', async interaction => {
if (!interaction.isButton()) return;
// Pause
if (interaction.customId === "PauseButton") {
    player.pause(true);
    const int = await interaction.deferUpdate({
      fetchReply: true,
    });
    if (!int) return smt
    await int.edit({
      components: [ResumeButtons],
    });
    if(int.deleted) {
      interaction.channel.send()
    }
    }
// Resume
if (interaction.customId === "ResumeButton") {
    player.pause(false);
    const int = await interaction.deferUpdate({
      fetchReply: true,
    });
    if (!int) return smt
    await int.edit({
      components: [Buttons],
    });
    if(int.deleted) {
      interaction.channel.send()
    }
}

This returns the error DiscordAPIError: Unknown interaction ln line 23:13 await interaction.deferUpdate on await.

Basically, the code does the job (it works fully functional) except: On the First run, everything works fine, On the Second run, when I click any button, an error returns "Unknown interaction" and the reason is that the the code is running twice, I knew when I added console.log("PauseButton") on the interact, the log returned twice to console PauseButton PauseButton instead of once.

Meaning there are 2 listeners for the ineractionCreate or something? Do I need to remove any interaction when the message is removed?

I need help please, anything is appreciated!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The process was duplicating because I had an interactionCreate.js in that project. I felt so confused because there was so many files, code has no issues, my apologize.

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