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

283
Views
How to disable button after clicked on discord.js v12

Discord.js v12 Disable Buttons Function


how do I disable a button on discord.js after it is clicked? I tried using the collector.on function, since that seems to do it but I can't make it work with my code and I know, I didn't copy-paste but I can't seem to work it out and its stressing me a lot, i looked through all the web to get answers but nothing anywhere. the discord-buttons js guide just disappeared. Well you've come to the right place you can simply do the following below its explained and can really help you ๐Ÿ˜ƒ.


So because the last answer was not right but had some correct formats this is what you wanna do. The code is explained the best i can below


The Code:

// After you have made your buttons and the embed you then need to do
// You can do this method a lot of times just make sure to add a cooldown.
// You can also do the same with the MessageActionRow() constructor
const embed = new Discord.MessageEmbed().setColor('red').setDescription('click the below buttons').setTimestamp()
const dbutton = new MessageButton().setStyle('blurple').setID('lol').setLabel('disabled button').setDisabled(true).setEmoji('๐Ÿ˜ƒ')
const button = new MessageButton().setStyle('blurple').setID('yes').setLabel('enabled button').setEmoji('๐Ÿ˜ƒ')
const after = await message.channel.send({ embed: embed, components: [button] })

client.on("clickButton", async (button) => {
if (button.id === "yes") {
message.channel.send({ content: "you clicked the first button" })
after.edit({ embed: embed, components: [dbutton] })
} 
button.reply.defer();
});

The above embed: and components: are supported in v12. I hope this helped you with further questions

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

MessageButton class has a "setDisabled" method that you can set to true.

When done, it won't automatically disable it. You need to edit the embed, passing the components again.

     const button11 = 

    const row = new MessageActionRow()
        .addComponents(
             new MessageButton()
                 .setStyle('green')
                 .setID('yes')
                 .setLabel('Lock')
                 .setEmoji('๐Ÿ”’')
         )

    const supportembedy = new Discord.MessageEmbed()
                              .set(....)

    let botMsg = await channel.send(supportembedy, row);

    const filter = i => ((i.customId === "yes") || (i.customId === "no")) && i.user.id === message.author.id 
    const collector = interaction.channel.createMessageComponentCollector({filter, time: 15000})

    collector.on("collect", async (i) => {
        if (i.customId === 'yes') {
            row[0].setDisabled(true)
            // first way
            botMsg.edit({ embeds: [supportembedy], components: [row] })
            //second way
            i.update({ embeds: [supportembedy], components: [row] })
        }
    }
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!