NightDev Community Forums

External Javascript Countdown Not Working

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

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 in web browser console:
Screenshot 2021-03-24 210448

Output in Twitch chat:
Screenshot 2021-03-24 210835

1 Like

Hey @CountryMac1977!

Glad you figured it out. Just answering now because I find it interesting that Nightbot doesn’t read single line comments properly when it’s from a Pastebin, I’ve stored many commands in pastes and never had that issue because I didn’t comment the code. Anyway, my question is, was the paste text format set up to JS or simply text? I’m wondering if it would have recognized the comments if the format matched the language. Thank you for your edit btw, this will help us assist people in the future if someone experiences the same issue some day.


@EmilyPerrimon The syntax highlighting in the Pastebin is set to JS. Once I removed all the comments and changed the date string from double quotations to single quotations in the countDownDate variable it worked. Block commenting seems to work just fine though, FYI.

1 Like

Thank you very much for your precious feedback, we really appreciate it!

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