async def _extctl_unload(ctx: commands.Context, extension: str): try: bot.unload_extension(ext_dir + "." + extension) await cmn.add_react(ctx.message, cmn.emojis.check_mark) except commands.ExtensionError as ex: embed = cmn.error_embed_factory(ctx, ex, bot.qrm.debug_mode) await ctx.send(embed=embed)
async def _extctl_reload(ctx: commands.Context, extension: str): if ctx.invoked_with == "relaod": pika = bot.get_emoji(opt.pika) if pika: await cmn.add_react(ctx.message, pika) try: bot.reload_extension(ext_dir + "." + extension) await cmn.add_react(ctx.message, cmn.emojis.check_mark) except commands.ExtensionError as ex: embed = cmn.error_embed_factory(ctx, ex, bot.qrm.debug_mode) await ctx.send(embed=embed)
async def on_command_error(ctx: commands.Context, err: commands.CommandError): if isinstance(err, commands.UserInputError): await cmn.add_react(ctx.message, cmn.emojis.warning) await ctx.send_help(ctx.command) elif isinstance(err, commands.CommandNotFound): if ctx.invoked_with and ctx.invoked_with.startswith(("?", "!")): return else: await cmn.add_react(ctx.message, cmn.emojis.question) elif isinstance(err, commands.CheckFailure): # Add handling of other subclasses of CheckFailure as needed. if isinstance(err, commands.NotOwner): await cmn.add_react(ctx.message, cmn.emojis.no_entry) else: await cmn.add_react(ctx.message, cmn.emojis.x) elif isinstance(err, commands.DisabledCommand): await cmn.add_react(ctx.message, cmn.emojis.bangbang) elif isinstance(err, (commands.CommandInvokeError, commands.ConversionError)): # Emulating discord.py's default beaviour. print("Ignoring exception in command {}:".format(ctx.command), file=sys.stderr) traceback.print_exception(type(err), err, err.__traceback__, file=sys.stderr) embed = cmn.error_embed_factory(ctx, err.original, bot.qrm.debug_mode) embed.description += f"\n`{type(err).__name__}`" await cmn.add_react(ctx.message, cmn.emojis.warning) await ctx.send(embed=embed) else: # Emulating discord.py's default beaviour. (safest bet) print("Ignoring exception in command {}:".format(ctx.command), file=sys.stderr) traceback.print_exception(type(err), err, err.__traceback__, file=sys.stderr) await cmn.add_react(ctx.message, cmn.emojis.warning)