diff options
| -rw-r--r-- | bot/bot.py | 15 | 
1 files changed, 4 insertions, 11 deletions
diff --git a/bot/bot.py b/bot/bot.py index 9a60474b3..fbd97dc18 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -3,6 +3,7 @@ import logging  import socket  import warnings  from collections import defaultdict +from contextlib import suppress  from typing import Dict, List, Optional  import aiohttp @@ -134,20 +135,12 @@ class Bot(commands.Bot):          self._recreate()          super().clear() -    def _remove_extensions(self) -> None: -        """Remove all extensions to trigger cog unloads.""" -        extensions = list(self.extensions.keys()) - -        for ext in extensions: -            try: -                self.unload_extension(ext) -            except Exception: -                pass -      async def close(self) -> None:          """Close the Discord connection and the aiohttp session, connector, statsd client, and resolver."""          # Done before super().close() to allow tasks finish before the HTTP session closes. -        self._remove_extensions() +        with suppress(Exception): +            [self.unload_extension(ext) for ext in tuple(self.extensions)] +            [self.remove_cog(cog) for cog in tuple(self.cogs)]          # Wait until all tasks that have to be completed before bot is closing is done          log.trace("Waiting for tasks before closing.")  |