# thanks to https://github.com/imptype/BasicBot/tree/main for the example code this is forked from import os import asyncio import datetime import traceback import contextlib import aiohttp import discohook from starlette.responses import JSONResponse from cogs.utils import ping_command, timestamp_command, info_command from cogs.fun import decide_command, funfact_cmd, randomgif_cmd from cogs.games import rps_command, gtn_command from cogs.dice import dice_command, old_dice_command def run(): @contextlib.asynccontextmanager async def lifespan(app): try: yield finally: if app.http.session: await app.http.session.close() app = discohook.Client( application_id = os.getenv('DISCORD_APPLICATION_ID'), public_key = os.getenv('DISCORD_PUBLIC_KEY'), token = os.getenv('DISCORD_BOT_TOKEN'), password = os.getenv('SYNC_PASSWORD'), lifespan = lifespan ) error_log_webhook = discohook.PartialWebhook.from_url(app, os.getenv('ERROR_LOG_WEBHOOK')) @app.on_interaction_error() async def on_error(interaction, error): trace = tuple(traceback.TracebackException.from_exception(error).format()) text = ''.join(trace) print(text) if interaction.responded: await interaction.response.followup('An error occured in a followup message... ') else: await interaction.response.send('An error occured...') await error_log_webhook.send(text[:2000]) app.started_at = datetime.datetime.now(datetime.timezone.utc) app.add_commands( ### --- Cog: Utils --- ### ping_command, timestamp_command, info_command, ### --- Cog: Fun --- ### decide_command, funfact_cmd, randomgif_cmd, ### --- Cog: Games --- ### rps_command, gtn_command, ### --- Cog: Dice --- ### dice_command, old_dice_command, ) return app app = run()