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

266
Views
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 answers
Answer question

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 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!