Help with command $(query) verification

Hello!
Is there any way I can make it so a Nightbot command actually checks if the person said anything after doing the command, and only if they did say something it will throw a response, or maybe a different one?

I was looking into adding an !8ball command, but I would like to have it so the person has to actually say something after typing !8ball… otherwise… either nothing happens, or Nightbot tells them they need to ask something first. Is any of that possible without having to create a custom API?

Thanks in advance!

Try something like this:

!commands add !8ball $(eval var s = [‘No’, ‘Yes’, ‘Maybe’]; `$(querystring)`.trim() == ‘’ ? ‘Ask a question first’ : s[Math.floor(Math.random() * s.length)]:wink:

(Error is fixed in edit, also changed single quotes to grave accents as suggested here)

1 Like

Thanks for the response!
When I copy that line to make the command, I get the following reply from Nightbot:
Right-hand side of ‘instanceof’ is not an object
(Not a single clue what that means lol)

After pasting the command I tried going !8ball all by itself, then with a random text in, and then with text and a question mark at the end. Everything returns that same “right-hand side” reply o.o

Oh thats weird, it Just worked for me. Ill check in a bit.

1 Like

Weird! But thank you!
Yeah I’ve been trying some tiny adjustments here and there but honestly this is all quite beyond me. I haven’t seen this “.trim()” thing anywhere on the Nightbot documents like, a reference to know what all is possible to include in commands if that makes sense

You must’ve missed naming the array just retyping the command here xgerhard, try this instead monario:

!commands add !8ball $(eval var s = ['No', 'Yes', 'Maybe']; '$(querystring)'.trim() == '' ? 'Ask a question first' : s[Math.floor(Math.random() * s.length)];)

Also replying to your last post, .trim() is javascript, the $eval variable now allows you to use javascript in commands, allowing for much more complicated commands able to be created without the need for a custom api.

2 Likes

Oh yay that works perfectly now! Thank you so much! To both of you!

Are there any limitations to the kind of “javascript” things you can include in commands? or is it pretty much everything contained in the javascript language can be added to commands?

1 Like

@Stoupedog Ah yes thanks, good catch :slight_smile:

@Monario Glad it works now! I haven’t noticed any limitations yet, as long as the execution time is under a second, as described in the docs.

2 Likes

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