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

193
Views
¿Cómo verificar en un intervalo si ha pasado x tiempo desde la creación de un canal en discord.js?

He tenido dificultades para escribir esto y busqué mucho preguntas similares pero no encontré ninguna.

Así que tengo este esquema:

 new mongoose.Schema({ Guild: String, Username: String, UserID: String, Channel: String, Type: String, Reason: String, Time: Date, })

Y quiero eliminar automáticamente el canal después de x tiempo de su creación, el Time se guarda como <channel>.createdTimestamp

Y aquí está la condición del evento:

 setInterval(async () => { hSchema.find().then((data) => { if (!data && !data.length) return data.forEach(async (value) => { const user = value.UserID; var time = value.Time; // time of the creation of channel var res = time.getTime(); // time in ms // check if user is premium uSchema.findOne({ User: user}, async (err, userData) => { // if user is not premium if (!userData) { const destruct = ms('1m'); // time to pass before deleting var date = res + destruct; if () { // I can't figure out how to check if x time has passed since the creation of channel // Do stuff here const ch = data.Channel; const channel = client.channels.cache.get(ch) channel.delete() value.delete() } } }) }) }); }, ms("10 seconds"));

Entonces, como dije, solo necesito ayuda sobre cómo verificar si x ms ha pasado para usarlo en una declaración if() .

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede usar Date.now() para obtener la hora actual en milisegundos, luego restar el tiempo que necesite (en milisegundos) y compararlo con su marca de tiempo creada, si el número es mayor, ¡ha pasado más de un minuto!

 const minuteInMs = 60000; if (Date.now() - minuteInMs > channel.createdTimestamp) { console.log("more than a minute"); } else { console.log("less than a minute"); }
about 4 years ago · Juan Pablo Isaza Report

0

Puede usar el momento para restar la diferencia en segundos con bastante facilidad.

 var now = moment(new Date()); var end = moment(discordChannelCreationTimestamp); var duration = moment.duration(now.diff(end)); var seconds = duration.asSeconds();
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!