I’m trying to create Nightbot command that creates multiple random variables and them adds those variables together, for rolling dice. I’ve successfully figured out how to roll individual dice, and add “lucky” and “unlucky” type messages based on the result. The final is to make a “!rollall” command that rolls a complete dice set. It looks something like this:
/me $(user) rolls some dice! The results are:
D4 = $(eval let a=Math.floor(Math.random()*4)+1;`${a}!`)
D6 = $(eval let b=Math.floor(Math.random()*6)+1;`${b}!`)
D8 = $(eval let c=Math.floor(Math.random()*8)+1;`${c}!`)
D100 = $(eval let d=Math.floor(Math.random()*100)+1;`${d}!`)
D12 = $(eval let e=Math.floor(Math.random()*12)+1;`${e}!`)
D20 = $(eval let f=Math.floor(Math.random()*10)+1;`${f}!`)
Total = $(eval let g=${a}+${b}+${c}+${d}+${e}+${f}; `${g}!`)
The first 7 lines work great, generating unique random numbers within their specified ranges and displaying them properly. However, no matter how I try to format the last line I get some variation of broken. Some options are less broken than others, but I can’t figure out how to get it to simply add the variables I’ve generated before.
In searching before posting, I did find some posts that helped me get the individual dice commands working properly, but couldn’t find anything to help me add them together without it breaking.
As a secondary consideration, as-is the code gets very close to the 500 character limit. I would love to be able to make it shorter so that I could add some flavor text at the end regarding lucky or unlucky rolls. Is there a more concise way to generate a random number or etc.?