From 3709d79f5bd6778b37c27230dbb47c4591878bd3 Mon Sep 17 00:00:00 2001 From: Twentysix Date: Sun, 22 May 2016 23:00:47 +0200 Subject: [PATCH] Added !unload all Unloads all cogs at once --- cogs/owner.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/cogs/owner.py b/cogs/owner.py index 4c3b101e9..2b5eedeaf 100644 --- a/cogs/owner.py +++ b/cogs/owner.py @@ -75,7 +75,7 @@ class Owner: await self.disable_commands() await self.bot.say("Module enabled.") - @commands.command() + @commands.group(invoke_without_command=True) @checks.is_owner() async def unload(self, *, module: str): """Unloads a module @@ -102,6 +102,29 @@ class Owner: else: await self.bot.say("Module disabled.") + @unload.command(name="all") + @checks.is_owner() + async def unload_all(self): + """Unloads all modules""" + cogs = self._list_cogs() + still_loaded = [] + for cog in cogs: + set_cog(cog, False) + try: + self._unload_cog(cog) + except OwnerUnloadWithoutReloadError: + pass + except CogUnloadError as e: + log.exception(e) + traceback.print_exc() + still_loaded.append(cog) + if still_loaded: + still_loaded = ", ".join(still_loaded) + await self.bot.say("I was unable to unload some cogs: " + "{}".format(still_loaded)) + else: + await self.bot.say("All cogs are now unloaded.") + @checks.is_owner() @commands.command(name="reload") async def _reload(self, module):