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

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

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