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

209
Visualizações
Check how much time has passed since event called (discord.js)

I would like to know how i can check how much time has passed since an event (interactionCreate in my case) was fired, and do something after a certain amount. This is my current code:

  client.once('interactionCreate', interaction => {
                    if (!interaction.isButton()) return;

                    if (interaction.customId == '1') {
                        // do something 
                    } else {
                        // do something else
                    }

                })

It will check which of 2 buttons is pressed, but i also want to check if no button has been pressed in, let's say, 20 seconds, in that case it will do something different like sending a message but most importantly make it unable to interact with the 2 buttons.

How could i do this?

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

0

To do something certain time after the event is called, you shoud use setTimeout like this:

setTimeout(() => {
    // do something after 5 seconds
}, 5000)

You can create a variable where you store if another button was clicked or not, then, after the timeout, you check if the variable is true or false.

Your entire logic would look like this:

let buttonWasClicked = false;

client.once('interactionCreate', interaction => {
    if (!interaction.isButton()) return;
    if(!buttonWasClicked) buttonWasClicked = true;
    if (interaction.customId == '1') {
        // do something 
    } else {
        // do something else
    }
    setTimeout(() => {
        // after waiting 20 seconds
        if(buttonWasClicked) {
            // do something if a button was clicked
        } else {
            // do something if no button was clicked
        }
    }, 20000)
})
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