Random number command with arguments

Hello everyone,

So recently I wanted to add a command to my channel that would act kind of like the /roll command from World of Warcraft if you’re familiar with that, explanation :

The command is /roll, you can either have it with an argument or without, if you don’t put any argument, the following message is displayed for example : Numidia rolls 74 (1-100) - Meaning that without an argument, the command would always roll from 1 to 100. If you add a numerical argument to the command, for example /roll 8, the message displayed would be : Numidia rolls 7 (1-8)

Now I pretty much found a way to do it but there’s just one issue that you can see here :
c546bffb97820095cc5fc434b675b55d

I think it’s pretty self explanatory : If you add an argument to the command it’s pretty much perfect, but if you don’t you get that (null) text at the end of the command which is not really what I want, it should display 100 instead of null there.

Here the code that I’m using :

$(user) rolls $(customapi http://2g.be/twitch/randomnumber.php?=defstart=1&defend=100&start=1&end=$(1)) (1-$(1))

I hope I explain it well :smiley: , is there any way to fix that ?

@Numidia

You can write up the !roll command using $(eval) instead of using an RNG custom API. The following script outputs a random number between 1 and the input number and outputs a random number between 1 and 100 if the input doesn’t make sense, ie. the input doesn’t contain numbers or the input is a negative number.

!addcom -cd=5 !roll $(eval a=parseInt(decodeURIComponent(`$(querystring)`));b=a&&a>=1?a:100;`$(user) rolls ${Math.floor(Math.random()*b)+1} (1-${b})`)
1 Like

Thank you so much that’s exactly what I wanted :smiley:

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