diff --git a/discord/client.py b/discord/client.py index 78242691e..6fb3faba6 100644 --- a/discord/client.py +++ b/discord/client.py @@ -235,9 +235,7 @@ class Client: return self.ws def _get_state(self, **options: Any) -> ConnectionState: - return ConnectionState( - dispatch=self.dispatch, handlers=self._handlers, hooks=self._hooks, http=self.http, loop=self.loop, **options - ) + return ConnectionState(dispatch=self.dispatch, handlers=self._handlers, hooks=self._hooks, http=self.http, **options) def _handle_ready(self) -> None: self._ready.set() @@ -474,6 +472,11 @@ class Client: _log.info('logging in using static token') + loop = asyncio.get_running_loop() + self.loop = loop + self.http.loop = loop + self._connection.loop = loop + data = await self.http.static_login(token.strip()) self._connection.user = ClientUser(state=self._connection, data=data) @@ -611,9 +614,6 @@ class Client: TypeError An unexpected keyword argument was received. """ - self.loop = asyncio.get_running_loop() - self.http.loop = self.loop - self._connection.loop = self.loop await self.login(token) await self.connect(reconnect=reconnect) diff --git a/discord/http.py b/discord/http.py index b6a83def2..f73f55ab5 100644 --- a/discord/http.py +++ b/discord/http.py @@ -546,6 +546,7 @@ class HTTPClient: # Necessary to get aiohttp to stop complaining about session creation if self.connector is MISSING: self.connector = aiohttp.TCPConnector(loop=self.loop, limit=0) + self.__session = aiohttp.ClientSession( connector=self.connector, ws_response_class=DiscordClientWebSocketResponse, loop=self.loop ) diff --git a/discord/shard.py b/discord/shard.py index 4ba521965..417742acd 100644 --- a/discord/shard.py +++ b/discord/shard.py @@ -333,7 +333,6 @@ class AutoShardedClient(Client): self.__shards = {} self._connection._get_websocket = self._get_websocket self._connection._get_client = lambda: self - self.__queue = asyncio.PriorityQueue() def _get_websocket(self, guild_id: Optional[int] = None, *, shard_id: Optional[int] = None) -> DiscordWebSocket: if shard_id is None: @@ -426,6 +425,7 @@ class AutoShardedClient(Client): self._connection.shards_launched.set() async def connect(self, *, reconnect: bool = True) -> None: + self.__queue = asyncio.PriorityQueue() self._reconnect = reconnect await self.launch_shards() diff --git a/discord/state.py b/discord/state.py index 3053df980..9e0569524 100644 --- a/discord/state.py +++ b/discord/state.py @@ -169,10 +169,10 @@ class ConnectionState: handlers: Dict[str, Callable], hooks: Dict[str, Callable], http: HTTPClient, - loop: asyncio.AbstractEventLoop, **options: Any, ) -> None: - self.loop: asyncio.AbstractEventLoop = loop + # Set later, after Client.login + self.loop: asyncio.AbstractEventLoop = utils.MISSING self.http: HTTPClient = http self.max_messages: Optional[int] = options.get('max_messages', 1000) if self.max_messages is not None and self.max_messages <= 0: