Trouble with custom command/ Variables $(query)), $(eval)

Asked Aug 2, 2022·2 replies·Last activity 4 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'm new to nightbot and i'm trying to set up a few multi thread responses for a command (using pastebin.com)

One example was having people spam "can i join" so i wanted to set up that nightbot picks that up and will send out one of a few different responses.

Here is what i have so far, with the command being labelled as can i join:

$(can i join $(query) ).$(user), $(eval a="$(urlfetch json https://pastebin.com/raw/XXXXX".split(";");a[Math.floor(Math.random()*a.length)])

I have currently removed my "special code" for XXXXX, but have the correct one copied and pasted in my command code.

but when I go to use it in chat nothing happens?

Can someone please help me with wth i'm doing wrong, my brain hurts..

2 replies

give your pastebin link .
so we can check if something is wrong with the pastebin text

Hey @Fair Dragon!

I'm not sure how you got to that bit of code, haha! A topic such as this one should have helped.

Assuming the Pastebin content's syntax is correct for the way you create the array of possible responses, this is how you add such command through the chat:

!addcom can $(eval a = `$(urlfetch json https://pastebin.com/raw/XXXXXXXX)`.split(`;`); '$(query)'.toLowerCase().includes('i join') ? a[Math.floor(Math.random() * a.length)] : ' ';)

Here the command name is "can", then we check if the message contains "I join" (it doesn't include the "can" word because that's the command name), if that's the case we output a random answer, else we don't answer.