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

298
Visualizações
Should I use setTimeout() in production with discord.js?

I'm working on a bot and I want to set state of a button from enable to disabled.

here, I'm confused as if I should use setTimeout() to disable button after 20 seconds or leave it as it is. As setTimeout() is called everytime when user uses "!purchases" command.

setTimeout(() => {
    row.components[0].setDisabled(true);
    row.components[1].setDisabled(true);
    row.components[2].setDisabled(true);
    sentMessage.edit({
        content: 'You cannot interact with buttons now!',
        components: [row],
    });
}, 20000);

After what I've searched on google I've found that setTimeout() works in a async manner which mean if I've process1 as my main discord bots reply, process2, process3 and process4 are setTimeout() then node.js will not execute all these operations in parallel instead it will execute process1 if process2 is fetching or sending data, and vice versa.

Q0) is what I've found incorrect or has information missing?

Q1) So is it recommended in this scenario to use setTimeout()?

Q2) Will setTimeout() compound over the time or not?

Q3 Will there be any perfomence issue due to setTimeout()

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

0

I think you found some good information, but you may not fully understand it.

About asynchronous nature of setTimeout() from MDN

setTimeout() is an asynchronous function, meaning that the timer function will not pause execution of other functions in the functions stack. In other words, you cannot use setTimeout() to create a "pause" before the next function in the function stack fires.

So your setTimeout() should not block other functions.

Answering to other questions:

I think that use of setTimeout() here is correct.

The setTimeout should not compound over time - each setTimeout gets a unique timeoutID and it is returned as positive integer value of setTimeout() function.

There should not be performence issues.

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