Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to know what today is, in discord.js

I want to make bot that know what day is today, i have example code below but i dont know how to fix this.

  client.on("message", msg =>{
  if (msg.content === "!today"){
    If (Today is Sunday){
        msg.reply("Time to Holiday")
      }
    else if(Today is monday){
        msg.reply("Time to work")
      }
  }
 });

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

new Date() gives you the current date and time. It has a method .getDay() which gives you the day of the week as a number. Sunday is 0; Monday is 1. So:

const dayOfWeek = new Date().getDay();

if (dayOfWeek === 0) { // is it Sunday?

Note that this is the bot server date and time. Different users might be on different days, due to time zones.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading