aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2020-11-07 09:45:19 +0200
committerGravatar ks129 <[email protected]>2020-11-07 09:45:19 +0200
commit027666f95ccaf07dfc73d2bfb7487e5a61bcd2d2 (patch)
tree4797316b7e9f77ea5c47afe94cd6bdbef498956e
parentMerge branch 'master' into bug-fixes (diff)
Remove both cogs and extensions on closing
-rw-r--r--bot/bot.py15
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.")