-1

I would like to make bot that in specific time every day will for example message but i want that the bot can still response to commands. Is there any node.js library or some function.

michal_cz17
  • 13
  • 1
  • 2
  • 1
    This seems like more of a question you should research about and ask around. Not for Stack Overflow – Elitezen Apr 21 '21 at 21:22
  • Does [this question](https://stackoverflow.com/questions/4455282/call-a-javascript-function-at-a-specific-time-of-day) help you? – Toasty Apr 21 '21 at 22:22

1 Answers1

0

You can use the cron package to do this. You first have to import CronJob:

const { CronJob } = require('cron');

If you want to scedule a message at 17:18 everyday, you define a CronJob like this:

const job = new CronJob('0 18 17 * * *', () => {
    //send a message
});

and start it:

job.start();

the format for the string is 'sec min hour day of month month day of week'. You use * if all values of that parameter is accepted. Your callback function will be called everytime all 6 of the paremeters match the current time. The sec parameter must not be *, or else the message would get sent every second in that minute.

Eden
  • 48
  • 6