import random from discord.ext import commands class Fun(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot @commands.hybrid_command(name="roll") async def roll(self, ctx: commands.Context, dice: str = "1d6"): """Roll dice in NdM format (e.g., 2d6).""" try: rolls, faces = map(int, dice.lower().split("d")) except Exception: return await ctx.send("Format has to be NdM, e.g. 2d6.") results = [random.randint(1, faces) for _ in range(rolls)] await ctx.send(f"Rolled {dice}: {results} (total {sum(results)})") @commands.hybrid_command(name="flip") async def flip(self, ctx: commands.Context): """Flip a coin.""" await ctx.send(random.choice(["Heads", "Tails"])) async def setup(bot: commands.Bot): await bot.add_cog(Fun(bot))