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

198
Vistas
How to check in an interaval if x time has passed since the creation of a channel in discord.js?

I've been having some hard time writing this and I searched a lot for any similar questions but didn't find any.

So I have this Schema:

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

And I want to automatically delete the channel after x time of its creation, the Time is saved as <channel>.createdTimestamp

And here is the condition of the event:

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"));

So as I said I just need some help on how to check if x ms has passed to use it in an if() statement!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use Date.now() to get the current time in milliseconds, then subtract whatever time you need (in milliseconds), and check that versus your created timestamp, if the number is greater it's been more than a minute!

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 Denunciar

0

You can use moment to subtract the diff in seconds pretty easy.

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 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