Reversing a string with nightbot eval commands

Asked Feb 1, 2020·2 replies·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.

Trying to make a command that flips the characters in a string from user input after the command, so "hello world!" turns into "!dlrow olleh". I keep getting the "Right-hand side of 'instanceof' is not an object" response from nightbot can anyone help with my code and tell me what's wrong?

!addcom !reverse $(eval const n = '$(query)'; const r = n.split(); const v = r.reverse(); const f = v.join(); ? f;)

I'm not a programer so sorry if it's all wrong.

2 replies

If the command you're using is directly copy-pasted, you have to change the quotes you're using - This should work: '$(query)'

You'll also have to add an empty string when splitting, or else it won't actually split - This should work: n.split('')

EDIT: Seems you'll also have to remove that ? at the end, as well as putting '' inside the v.join(''), or else it defaults to comma.
Full command should look something like:

Thank you so much been trying to figure out what I had wrong all day! You rock!

Edit: If anyone is viewing this at a future date a cleaner code for the command is

!commands add !reverse $(eval var n = '$(query)'; var o = n.split('').reverse().join(''); o;)

Edit2: or even just

!commands add !reverse $(eval '$(query)'.split('').reverse().join(''); )