0
votes

I was wondering how I would be able to make a discord bot that would repeat a message every Monday and Wednesday and Friday at 9:45 AM PST.

I'm using discord.js and I have the message working perfectly fine, just can't figure out how to send the message at the specific time and date.

1
This may answer your question stackoverflow.com/questions/53820970/…GrumpyCrouton
tried the example given and it didn't workBrand0n_

1 Answers

0
votes

Since you already have the message set up, here's how you fire the message at specific times.

let timer = setInterval(function() {
  const now = new Date(); // for reference, PST is UTC-8, and I'm assuming you don't want to account for the nightmare that is daylight savings time
  if (now.getDay() == 1 || now.getDay() == 3 || now.getDay() == 5) { // check if it's monday, wednesday, or friday
    if (now.getUTCHours() - 8 == 9 && now.getUTCMinutes() == 45) { // confirm that it's 5:45 pm UTC, or 9:45 am PST
      sendTime(); // note that this won't say what day in particular it is, but that's probably fine
    }
  }
}, 60 * 1000); // fire the function only every minute to prevent insane lag.

I should probably suggest doing a little bit of alignment to make sure the bot doesn't send the time message just as the clock strikes 9:46, assuming you care about that.