JavaScript with NightBot

Asked Feb 10, 2020·1 reply·Last activity 6 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

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?

1 reply

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: (link expired), (link expired))
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';