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

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

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