File size: 860 Bytes
7cc32a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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))