NightDev Community Forums

Nightbot "right-hand side of instance of is not an object"

Code:
!commands add !roll25 $(eval var s=“yes”; if{("$(1)" == “null”) s=“no”};s;)
Not sure where I went wrong, please fix (what else can i say?)

!commands add !roll25 $(eval decodeURIComponent(`$(querystring)`)?`yes`:`no`)

Thanks for the fast reply, will try it out.

ok, it worked! thanks for the quick reply given very little context, and it’s a one-liner (well, no semicolons one-liner) now!

ok i tried to add another ternary operator and now I’m even more confused:

!commands edit !roll25 $(eval decodeURIComponent(`$(querystring $(2))`)?$(1)+Math.floor(Math.random() * ($(2)-$(1))):decodeURIComponent('$(querystring $(1))')?Math.floor(Math.random() * $(1)):Math.floor(Math.random() * 100))

Basically, this is the same thing you had before but in the first ternary operator, if there is a second argument then we will roll a number between the second and first argument

but if there is no second argument, then check to make sure there is a first argument. If so, then roll a number between 0 and that first argument.

If not, roll a random number between 1 and 100. Now the last part is where I have issues.

My command works for the first two cases (2 and 1 arguments) but in the third case returns 0 at all times, this is quite confusing.
Edit: and just to clarify, if there are no arguments for some reason the whole eval returns 0 before even running the second half of the second ternary statement, for some reason…

Wrote some new code.

$(eval a=decodeURIComponent(`$(querystring)`).split(` `).slice(0,2).map(x=>parseInt(x)).filter(x=>!isNaN(x));if(a.length==0){a.push(0,100);}if(a.length==1){a.push(0);}a.sort((x,y)=>x-y);(a[0]+Math.floor(Math.random()*(a[1]-a[0]+1))).toString().slice(0,400))

You can input 0, 1, or 2 integers (i.e. >0 or <0).