Edit: I figured it out… Javascript single line comments don’t work with Nightbot and Pastebin.
I’m trying to write external Javascript to work as a countdown command to output a countdown depending on certain times of day and the week. For now I’m just trying to get a single countdown string to output in chat and then build onto the script. Yes, I’m familiar with the Nightbot $(countdown) variable, but it won’t work for the purpose of my script.
The Javascript code works as intended in a web browser console, but when I try it with a Nightbot command, it returns an “undefined” error as the chat message. What am I doing wrong here?
Nightbot command:
!addcom !countdown $(eval $(urlfetch json https://pastebin.com/raw/yCnnEkww))
External Javascript:
var countDownDate = new Date(‘Sep 25, 2025 15:00:00’).getTime();
// Get todays date and time
var now = new Date().getTime();// Find the distance between now an the count down date
var distance = countDownDate - now;// Time calculations for days, hours, minutes and seconds
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);// Output result
var output = hours + "h " + minutes + "m " + seconds + "s ";output;
Output in web browser console:
Output in Twitch chat: