Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!