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

80
Vistas
setInterval Not Repeating Function using Discord.js

I'm trying to make a discord bot that gives you weekly reminders. Im using momentjs to get the time. As well as using discord.js-commando. I found the best way to call a function multiple times is to use setInterval.

const moment = require('moment');
const Commando = require('discord.js-commando');
const bot = new Commando.Client();

bot.on('ready', function () {
  var day = moment().format('dddd');
  var time = moment().format('h:mm a');

  function Tuesday() {
    if (day == 'Tuesday' && time == '6:30 pm') {
      const channel = bot.channels.get('933047404645724234');
      console.log('Sending Message');
      channel.send('Reminder: You have a week to complete your To-Do List!');
    } else {
      console.log('Not Sending Message');
    }
  }

  console.log('Bot is now ready!');
  setInterval(Tuesday, 100);
});

I noticed the problem with the setInterval is that it is only called once. I also tried using an async function but that failed as well.

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

0

Well executing a function every 100ms is not quite optimal. I don't know what is the reason to run just once (it should run infinitely) but there is a better way to do what you need.

You will need the package called "node-schedule". It's really useful for such things.

Here's an example:

const schedule = require("node-schedule");

schedule.scheduleJob({hour: 18, minute: 30, dayOfWeek: 2}, function(){
    // your code here
});

You can read more in the documentation of node-schedule here.

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