From 915b9b8caae95e26e873ab6c49f7604c941bdd1d Mon Sep 17 00:00:00 2001 From: dolfies Date: Sat, 6 May 2023 16:50:28 -0400 Subject: [PATCH] Refactor HTTP client lifecycle --- discord/http.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/discord/http.py b/discord/http.py index b80889e06..64270ee02 100644 --- a/discord/http.py +++ b/discord/http.py @@ -616,6 +616,11 @@ class HTTPClient: if self._started: return + self._global_over = asyncio.Event() + self._global_over.set() + + if self.connector is MISSING or self.connector.closed: + self.connector = aiohttp.TCPConnector(limit=0) self.__session = session = await _gen_session( aiohttp.ClientSession( connector=self.connector, trace_configs=None if self.http_trace is None else [self.http_trace] @@ -693,6 +698,9 @@ class HTTPClient: captcha_handler = self.captcha_handler route_key = route.key + if not self._started: + await self.startup() + bucket_hash = None try: bucket_hash = self._bucket_hashes[route_key] @@ -1052,14 +1060,6 @@ class HTTPClient: async def static_login(self, token: str) -> user.User: old_token, self.token = self.token, token - if self.connector is MISSING: - self.connector = aiohttp.TCPConnector(limit=0) - - self._global_over = asyncio.Event() - self._global_over.set() - - await self.startup() - try: data = await self.get_me() except HTTPException as exc: