From 2216b70e3414365d1299eddaf2527f49f19b7543 Mon Sep 17 00:00:00 2001 From: bibin Date: Mon, 4 Jan 2021 02:32:45 +0100 Subject: [PATCH] Feat: Add emoji confirming/error reactions If the commands throws an error then the bot marks the command message with a cross emoji reaction otherwise it adds a check mark. (Also resolved some overshadowing warning of extension) --- src/bot.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/bot.py b/src/bot.py index 37eed11..6bad9a9 100644 --- a/src/bot.py +++ b/src/bot.py @@ -10,6 +10,8 @@ __author__ = 'Bibin Muttappillil' # standard library imports import os from dotenv import load_dotenv +import sys +import traceback # discord imports from discord.ext import commands @@ -25,25 +27,37 @@ if TOKEN is None: bot = commands.Bot(command_prefix=commands.when_mentioned_or('$b ')) -@bot.command(hidden=True) -@commands.is_owner() -async def load(ctx, extension): - bot.load_extension(f'cogs.{extension}') - print(f'cogs.{extension} loaded') +@bot.event +async def on_command_error(ctx, error): + print('Ignoring exception in command {}:'.format(ctx.command), file=sys.stderr) + traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr) + await ctx.message.add_reaction('❌') + + +@bot.event +async def on_command_completion(ctx): + await ctx.message.add_reaction('✅') @bot.command(hidden=True) @commands.is_owner() -async def unload(ctx, extension): - bot.unload_extension(f'cogs.{extension}') - print(f'cogs.{extension} unloaded') +async def load(ctx, ext): + bot.load_extension(f'cogs.{ext}') + print(f'cogs.{ext} loaded') @bot.command(hidden=True) @commands.is_owner() -async def reload(ctx, extension): - bot.reload_extension(f'cogs.{extension}') - print(f'cogs.{extension} reloaded') +async def unload(ctx, ext): + bot.unload_extension(f'cogs.{ext}') + print(f'cogs.{ext} unloaded') + + +@bot.command(hidden=True) +@commands.is_owner() +async def reload(ctx, ext): + bot.reload_extension(f'cogs.{ext}') + print(f'cogs.{ext} reloaded') for extension in ['developer']: