Trying to use :) with eval

So i’m trying to do a simple random response command and i want to use the smiley face emote as one of the responses and i’m always getting the same error

Right-hand side of ‘instanceof’ is not an object

!commands add !c $(eval a=[’:)’,‘2’,‘3’];a[Math.floor(Math.random()*a.length)])

@siron

Nightbot uses parenthesis pairs to interpret where variables start and end. Every variable must start with a dollar sign and left parenthesis “$(” and must end with a right parenthesis “)

Nightbot should interpret the right parenthesis all the way at the end of the command response as the end of the $(eval) variable. However, the first string in the array is “:)” and it contains a right parenthesis, so Nightbot interprets this as the end of the variable instead, resulting in an error.

That said, a workaround exists. You can use the String.fromCharCode() method to convert Unicode numbers into characters:

!addcom -cd=5 !c $(eval a=[String.fromCharCode(58,41),`2`,`3`];a[Math.floor(Math.random()*a.length)])

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