-2

I am struggling to find any tutorial or help on this issue. I simply want the bot to send a message in a channel saying "Today is {day of the week}" every day. Anyone know how to go about this?

1 Answers1

1

Get the day of the week

const now = new Date();
const weekdays = [
  "Sunday",
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday"
];
const day = weekdays[now.getDay()];
console.log(day);

Send it every day

This very good answer seems to answer your question. Applied to your problem:

const cron = require("cron");

function getDay() {
  return [
    "Sunday",
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
  ][new Date().getDay()];
}

function greeting() { // To be fired
  const channel = your_channel;
  return channel.send(`Today is ${getDay()}!`);
}

const dailyGreeting = new cron.CronJob("00 00 08 * * *", greeting); // Fires every day at 08:00:00 AM
dailyGreeting.start(); // Start the job
deb
  • 6,671
  • 2
  • 11
  • 27