From 108e9abb5264d02056e5106fd89488ee122510f7 Mon Sep 17 00:00:00 2001 From: Jakub Kuczys Date: Wed, 4 Mar 2026 22:01:50 +0100 Subject: [PATCH] Avoid AttributeError on AutoShardedClient.close() call before async setup --- discord/shard.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/discord/shard.py b/discord/shard.py index 7198887cf..b01818bf8 100644 --- a/discord/shard.py +++ b/discord/shard.py @@ -41,6 +41,7 @@ from .errors import ( ConnectionClosed, PrivilegedIntentsRequired, ) +from .utils import MISSING from .enums import Status @@ -389,6 +390,7 @@ class AutoShardedClient(Client): self.__shards = {} self._connection._get_websocket = self._get_websocket self._connection._get_client = lambda: self + self.__queue: asyncio.PriorityQueue = MISSING def _get_websocket(self, guild_id: Optional[int] = None, *, shard_id: Optional[int] = None) -> DiscordWebSocket: if shard_id is None: @@ -554,7 +556,8 @@ class AutoShardedClient(Client): await asyncio.wait(to_close) await self.http.close() - self.__queue.put_nowait(EventItem(EventType.clean_close, None, None)) + if self.__queue is not MISSING: + self.__queue.put_nowait(EventItem(EventType.clean_close, None, None)) self._closing_task = asyncio.create_task(_close()) await self._closing_task