If/Then loop to return message during certain times of the day

Hello! I am trying to make a command that will return a message if my current time is in between a certain time frame, but I keep getting error messages like “unexpected identifier” and “Unexpected token ‘<=’”. I’ve searched the forums and google and I’m not new to coding but JS is a bit confusing, so would appreciate any help/suggestions!

Command code:
$(eval var a = “$(time timezone “H:mm”)”;
var b = false;
if (a >= “22:30” && <= “6:00”) b = true;
else if (a >= “6:00” && <= “22:30”) b = false;)

Hey @bb21!

Here’s the thing: 22:30 and 6:00 aren’t numbers, but text, therefore you can’t use the greater/lesser than comparison.
You can however get numbers from the $(time) variable, and then do the comparison.
Also, I understand that true is for the time period it’ll send a message, and false should result in no message, if that’s not the case, your explanation isn’t clear.
I’ll also simplify your code a bit:

$(eval t=parseInt($(time TIMEZONE "Hmm")); o=` `; if(t>=2230 && t<=600){o=`MESSAGE`} o;)

Replace the TIMEZONE and MESSAGE fields.

1 Like

That worked, thank you so much!!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.