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

267
Visualizações
Discord.js how use button several times
const filter = (interaction) => {
    if (interaction.user.id === message.author.id) return true;
    return interaction.reply({
        content: "An error has occurred",
        ephemeral: true
    })
}

const collectorValue1 = message.channel.createMessageComponentCollector({
    filter,
    max: 1
})

collectorValue1.on("end", (ButtonInteraction) => {
    const id = ButtonInteraction.first().customId;
    if (id == '1') {
        ButtonInteraction.first().reply({
            content: "CONTENT",
            ephemeral: true
        })
    } else if (id == '2') {
        ButtonInteraction.first().reply({
            content: "CONTENT",
            ephemeral: true
        })
    } else if (id == '3') {
        ButtonInteraction.first().reply({
            content: "CONTENT.",
            ephemeral: true
        })

    }
})

I would like when the buttons are created they are multiple executable, however I can only use the button once, after that I always get the message "This interaction failed." how can I make the buttons multiple executable?

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

0

Please try the following:

collectorValue1.on("end", (ButtonInteraction) => {
ButtonInteraction.deferUpdate();
    const id = ButtonInteraction.first().customId;
    if (id == '1') {
        ButtonInteraction.first().editReply({
            content: "CONTENT",
            ephemeral: true
        })

Use deferUpdate() in the same way on each of the if statements. However, please note that when using deferUpdate(), you will need to change the .reply() method to .editReply().

You might try putting the deferUpdate() in the filter definition.

There is not much guidance on the Discord.js website, or documentation on using deferUpdate(). However, glean what you can from the documentation. Here is an example from the docs:

// Defer updating and reset the component's loading state
interaction.deferUpdate()
  .then(console.log)
  .catch(console.error);

Notably, the comment mentions that it "resets the component's loading state". I believe this is related to how it allows for using a button several times.

I hope this was helpful :]

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