Simple Nightbot command to roll any number of any kind of dice
$(eval var i=parseInt,d=[],e='$(provider)'=='twitch'?'melziiD20':'🎲20',j=0,l,m='$(query)'.match(/^(([0-9]+)\s+)?(([0-9]+)?d([0-9]+)|([0-9]+))$/)??{},c=i(m[2]??1),n=i(m[4]??1),s=i(m[5]??m[6]??20);c=c>20?20:(c<1||!c?1:c);n=(n<1?1:n);s=(s<1?1:s);for(;j<c;j+=1){d.push(Math.round(n*(s-1)*Math.random())+n)}r=`$(user) rolled ${d.join(', ')} with ${n<2?'a ':n+'×'}🎲`+s;l=r.lastIndexOf(',');(l<0?r:r.substr(0,l)+' and'+r.substr(l+1)).replace(/( |🎲)20(,| |$)/g,` ${ e } $2`))
Examples:
!roll
- PakL rolled a 2 with a 🎲6
!roll 20
- PakL rolled a 14 with a 🎲20
!roll 2d6
- PakL rolled a 11 with 2×:game_die:6
Or something absurd like:
!roll 15d19
- PakL rolled a 118 with 15×:game_die:19
!roll 5d1
- PakL rolled a 5 with 5×:game_die:1
2021-05-25
Any 20 will be replaced by the emote. d20 is now the default instead d6 and I also added the capability to make up to 20 throws at once:
!roll 20 d20
- PakL rolled 13, 6, 4, , 8, 19, 19, 2, 13, 15, 6, 3, 5, 7, 12, 14, 10, 1, 11 and 5 with a
2022-07-08
- Fixed a bug that prevented users to use other dice than d20 when outputting multiple throws and prefexing dice with a "d". (Thanks @MontageTM)
- Removed Discord emote as bot cannot use them across servers anymore.
oh! thank you anyway! :)