from discord.ext import commands import random import re class Fun(commands.Cog): def __init__(self, bot): self.bot = bot self.last_member = None @commands.command() async def roll(self, message, *args): """ roll xdy+... """ # split content = content=" ".join(args) numb = re.split(r'[d+\s]+', content) print("content: ", content) rand = 0 i = 0 array = [] sumrand = 0 try: # multiple dice and range while i < int(numb[0]): rand = random.randint(1, int(numb[1])) array.append(rand) print("dice: ", array[i]) i += 1 # sum dice for j in array: sumrand += int(j) vse = 0 # count range array for g in numb: vse += 1 vse -= 1 i = 2 # sum dice + all after xdx+ while i <= vse: sumrand += int(numb[i]) i += 1 await message.channel.send(f"{message.author.display_name} Request: {content} Roll: {array} Result: {sumrand}") except: await message.channel.send("try xdx+x..") @commands.Cog.listener() async def on_ready(self): print('Fun cog has been loaded') async def setup(bot): await bot.add_cog(Fun(bot))