diff options
| author | 2020-02-15 11:21:09 -0800 | |
|---|---|---|
| committer | 2020-02-15 11:21:09 -0800 | |
| commit | 5cc4e360aee28832ace207d8df2fb17b487fbfe7 (patch) | |
| tree | 5c99c8ebde265573a66ec34df83524374dee9469 | |
| parent | Bot: override login() instead of start() (diff) | |
Bot: move connector/session recreation to a separate function
The function itself doesn't need to be a coroutine. It just has to be
called in a coroutine (or, more indirectly, in an async context?).
| -rw-r--r-- | bot/bot.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/bot/bot.py b/bot/bot.py index 1d187f031..e1b1d81dc 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -58,6 +58,11 @@ class Bot(commands.Bot): async def login(self, *args, **kwargs) -> None: """Re-create the connector and set up sessions before logging into Discord.""" + self._recreate() + await super().login(*args, **kwargs) + + def _recreate(self) -> None: + """Re-create the connector, aiohttp session, and the APIClient.""" # Use asyncio for DNS resolution instead of threads so threads aren't spammed. # Use AF_INET as its socket family to prevent HTTPS related problems both locally # and in production. @@ -73,5 +78,3 @@ class Bot(commands.Bot): self.http_session = aiohttp.ClientSession(connector=self._connector) self.api_client.recreate(connector=self._connector) - - await super().login(*args, **kwargs) |