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

414
Visualizações
How do you disable a button after 5 seconds (discord.js)

I'm not very familiar with discord.js buttons and need help disabling a button after 5 seconds to avoid spam but I don't know how. Here is my code:

const newEmbed = new Discord.MessageEmbed()
  .setColor('#2ACAEA')
  .setTitle("Commands")
  .setDescription("Page 1 of 2")
  .addFields(
    {name: '!jn help', value: 'This command'},
    {name: '!jn ping', value: 'Ping the bot.'},
    {name: '!jn coinflip', value: 'Flip a coin :D'},
    {name: '!jn amiadmin', value: 'Are you an admin? We can see!'}
  )
  .setFooter('Need more help? Join the support discord server.')
  .setImage('https://i.imgur.com/Ta0yst7.png');

const row = new Discord.MessageActionRow()
  .addComponents(
    new Discord.MessageButton()
      .setCustomId('2')
      .setLabel('>>')
      .setStyle('SUCCESS'),
  );

message.channel.send({embeds: [newEmbed], components: [row]});

setTimeout(function () {
  row.components[0].setDisabled(true);
}, 5000);

When I try, it doesn't output any errors. I think I'm just missing something. Can someone help me?

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

0

You're on the right track - you've done the first step, which is to change the button to be disabled after 5 seconds locally, but now you need to edit your message to reflect those changes online.

First, you have to store your sent message in a variable:

const sentMessage = await message.channel.send({ embeds: [newEmbed], components: [row] });

Then, in your setTimeout, you can edit the sentMessage like Dregg said in his comment:

// After you disable the button
sentMessage.edit({ embeds: [newEmbed], 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