From d45b3d4ff2c667079d1bda962188ebb0bc54be64 Mon Sep 17 00:00:00 2001 From: Phxntxm Date: Sat, 9 Jul 2016 09:57:57 -0500 Subject: [PATCH] Added error checking to view the errors on loading, unloading modules --- cogs/mod.py | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/cogs/mod.py b/cogs/mod.py index e453fc4..a0bf7c0 100644 --- a/cogs/mod.py +++ b/cogs/mod.py @@ -26,32 +26,44 @@ class Mod: @checks.isAdmin() async def load(self, *, module : str): """Loads a module""" - if not len(module) > 0: - await self.bot.say("Please provide a module!") - return - self.bot.load_extension(module) - await self.bot.say("I have just loaded the {} module".format(module)) + try: + if not len(module) > 0: + await self.bot.say("Please provide a module!") + return + self.bot.load_extension(module) + await self.bot.say("I have just loaded the {} module".format(module)) + except Exception as e: + fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' + await bot.say(fmt.format(type(e).__name__, e)) @commands.command() @checks.isAdmin() async def unload(self, *, module : str): """Unloads a module""" - if not len(module) > 0: - await self.bot.say("Please provide a module!") - return - self.bot.unload_extension(module) - await self.bot.say("I have just unloaded the {} module".format(module)) + try: + if not len(module) > 0: + await self.bot.say("Please provide a module!") + return + self.bot.unload_extension(module) + await self.bot.say("I have just unloaded the {} module".format(module)) + except Exception as e: + fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' + await bot.say(fmt.format(type(e).__name__, e)) @commands.command() @checks.isAdmin() async def reload(self, *, module : str): """Reloads a module""" - if not len(module) > 0: - await self.bot.say("Please provide a module!") - return - self.bot.unload_extension(module) - self.bot.load_extension(module) - await self.bot.say("I have just reloaded the {} module".format(module)) + try: + if not len(module) > 0: + await self.bot.say("Please provide a module!") + return + self.bot.unload_extension(module) + self.bot.load_extension(module) + await self.bot.say("I have just reloaded the {} module".format(module)) + except Exception as e: + fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' + await bot.say(fmt.format(type(e).__name__, e)) def setup(bot):