I'm doing an event on my Discord server, and I need this to automatically run once a day, but at a random time. Can you guys give me an explanation or example of how I do it?
I have already seen node-cron, but apparently they just run at specific moments of the day.
I think the following would be a good idea to run once a day at a random time.
const { setTimeout } = require("timers/promises");
cron.schedule("0 0 * * *", async () => {
await setTimeout(Math.floor(Math.random() * 86400000 /* 1 day mill-seconds */));
// do stuff
});