Chitanda-Bot / cogs /fun.py
E5K7's picture
Initial commit: Discord bot with hybrid commands, Flask keep-alive, and Docker support
7cc32a6
raw
history blame contribute delete
860 Bytes
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))