Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @commands.command(aliases=['rtd'], description='usage: roll, roll 2, roll 8d12, roll 5d20+8')
- async def roll(self, ctx, adxopb=None):
- '''(rtd) Rolls dice in AdX+B notation. Default 1d6+0'''
- adxopb = adxopb.lower()
- op, b, opb = '', 0, ''
- if adxopb is None:
- adx = adxopb = '1d6'
- elif adxopb.isdigit(): # if no 'd':
- adx = adxopb = f'{adxopb}d6' # default all d6
- elif '+' in adxopb:
- adx, op, b = adxopb.partition('+')
- opb = f'{op}{b}'
- elif '-' in adxopb:
- adx, op, b = adxopb.partition('-')
- opb = f'{op}{b}'
- else:
- adx = adxopb
- try:
- a, x = map(int, adx.split('d')) # extract numbers
- rolls = [random.randrange(1, x+1) for die in range(a)]
- total = self.ops[op](sum(rolls), int(b)) # sum of all rolls +/- b
- except ValueError as e:
- await ctx.send(f":interrobang: Invalid input: `{adxopb}`. Only `0-9 d + -` allowed.")
- else:
- rolls = ' '.join(list(map(str, rolls)))
- output = f"🎲 **{total}** | *{ctx.author.display_name} rolled {adxopb.lower()}* ```x1\n{rolls} ({opb})```"
- await ctx.message.delete()
- await ctx.send(output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement