1

According to my codes, I want to send an auto msg when the certain time that I set. But it is not executing. Do my codes have a problem?

//time
var date = new Date();

var hour = date.getHours();
hour = (hour < 10 ? "0" : "") + hour;

var min  = date.getMinutes();
min = (min < 10 ? "0" : "") + min;

console.log(hour + ":" + min);

bot.on("message", function(msg){
  if(hour == 19 && min == 50){
    bot.sendMessage(msg.chat.id, "7:50 PM")
  }
});

I expect the output of "7:50" msg in my Bot, but nothing in my bot despite of 7:50 PM now.

P.S. the msg that printed in the console is correct with the current time.

Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
  • doing like your doing would require a message to be sent at that time to trigger it plus setting the values out of scope, they wont change. most likely you want to look into a queue or a simple interval loop https://stackoverflow.com/questions/33605072/run-function-at-set-interval-only-at-certain-time-of-the-day – Lawrence Cherone Nov 09 '19 at 11:07

0 Answers0