diff options
| author | Rapptz <[email protected]> | 2021-08-10 22:58:02 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-08-10 23:00:24 -0400 |
| commit | 6e6c8a7b2810747222a938c7fe3e466c2994b23f (patch) | |
| tree | 4890629c984158d6b206b5b7c40f967f8d7f7fbf /discord/http.py | |
| parent | Clarify StageInstance.discoverable_disabled documentation (diff) | |
| download | discord.py-6e6c8a7b2810747222a938c7fe3e466c2994b23f.tar.xz discord.py-6e6c8a7b2810747222a938c7fe3e466c2994b23f.zip | |
Refactor Client.run to use asyncio.run
This also adds asynchronous context manager support to allow for
idiomatic asyncio usage for the lower-level counterpart. At first
I wanted to remove Client.run but I figured that a lot of beginners
would have been confused or not enjoyed the verbosity of the newer
approach of using async-with.
Diffstat (limited to 'discord/http.py')
| -rw-r--r-- | discord/http.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/discord/http.py b/discord/http.py index b186782f..5a31928b 100644 --- a/discord/http.py +++ b/discord/http.py @@ -167,7 +167,7 @@ class HTTPClient: loop: Optional[asyncio.AbstractEventLoop] = None, unsync_clock: bool = True ) -> None: - self.loop: asyncio.AbstractEventLoop = asyncio.get_event_loop() if loop is None else loop + self.loop: asyncio.AbstractEventLoop = MISSING if loop is None else loop # filled in static_login self.connector = connector self.__session: aiohttp.ClientSession = MISSING # filled in static_login self._locks: weakref.WeakValueDictionary = weakref.WeakValueDictionary() @@ -371,6 +371,7 @@ class HTTPClient: async def static_login(self, token: str) -> user.User: # Necessary to get aiohttp to stop complaining about session creation + self.loop = asyncio.get_running_loop() self.__session = aiohttp.ClientSession(connector=self.connector, ws_response_class=DiscordClientWebSocketResponse) old_token = self.token self.token = token |