sir-rollington/bot.py

47 lines
905 B
Python

import discord
from discord.ext import commands
from discord.ext.commands.context import Context
from os import environ
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:
text = []
for die in dice:
roll = die.roll()
text.append(f"{die.text} => {roll} = {sum(roll)}")
print(text)
except DiceTextError as e:
print(e)
await ctx.send(str(e))
return
await ctx.send("\n".join(text))
token = environ.get("DISCORD_TOKEN")
if token is None:
print("Could not load token")
quit()
bot.run(token)