Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda