sir-rollington/bot.py

47 lines
905 B
Python
Raw Normal View History

2025-01-15 08:54:17 -05:00
import discord
from discord.ext import commands
from discord.ext.commands.context import Context
2025-01-15 22:00:37 -05:00
from os import environ
2025-01-15 08:54:17 -05:00
from dice import Dice, DiceTextError
prefix = "$"
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix=prefix, intents=intents)
@bot.event
async def on_ready():
print("Hello World!")
@bot.command()
async def roll(ctx: Context, *args: str):
dice = []
for arg in args:
dice.append(Dice(arg))
try:
2025-01-16 13:19:52 -05:00
text = []
for die in dice:
roll = die.roll()
text.append(f"{die.text} => {roll} = {sum(roll)}")
print(text)
2025-01-15 08:54:17 -05:00
except DiceTextError as e:
print(e)
await ctx.send(str(e))
return
2025-01-16 13:19:52 -05:00
await ctx.send("\n".join(text))
2025-01-15 08:54:17 -05:00
2025-01-15 22:00:37 -05:00
token = environ.get("DISCORD_TOKEN")
if token is None:
print("Could not load token")
quit()
bot.run(token)