NightDev Community Forums

JavaScript with NightBot

I am creating a song-request command (yes I know there is already one) and I am using the command !sr.
My command says:

$(eval a=$(urlfetch json http s://pastebin.com/AgHEzit1))
(space in between http and s to not make it a link in the forum)

My JavaScript says:

if ($(1) == null) {
$(user) you have to type a song name!
} else {
$(user) requested $(query)!
}

This doesn’t work and comes back with:

Right-hand side of ‘instanceof’ is not an object

What can I do to fix this?

Hiya, there’s a couple things that don’t work in your example. You’re storing the urlfetch result inside variable a, however the variable is never used.
Nightbot variables are not directly available in your pastebin code. I would suggest writing the pastebin code as a function, and call that function from the Nightbot command.
(Examples here: How to make Nightbot evaluate external JS code, with $query as a parameter?, Grab function from pastebin)
Also make sure you treat the Nightbot variables as strings: '$(1)'.
Same goes for the text you want to display inside in your JS if/else code, make the code return something:

if(something)
    return 'test';

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