sir-rollington/bot.py

45 lines
841 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:
results = ["(" + ",".join(d.roll()) + "," for d in dice]
except DiceTextError as e:
print(e)
await ctx.send(str(e))
return
msg = ",".join(results)
print(msg)
await ctx.send(msg)
token = environ.get("DISCORD_TOKEN")
if token is None:
print("Could not load token")
quit()
bot.run(token)