Reversing a string with nightbot eval commands

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.

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:
!commands add !rev $(eval const n = '$(query)'; const r = n.split(''); const v = r.reverse(); const f = v.join(''); f;)

1 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(’’); )

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