diff --git a/discord/shard.py b/discord/shard.py index 5495511a2683..fc8e3380a642 100644 --- a/discord/shard.py +++ b/discord/shard.py @@ -326,6 +326,11 @@ class AutoShardedClient(Client): ------------ shard_ids: Optional[List[:class:`int`]] An optional list of shard_ids to launch the shards with. + shard_connect_timeout: Optional[:class:`float`] + The maximum number of seconds to wait before timing out when launching a shard. + Defaults to 180 seconds. + + .. versionadded:: 2.4 """ if TYPE_CHECKING: @@ -334,6 +339,8 @@ class AutoShardedClient(Client): def __init__(self, *args: Any, intents: Intents, **kwargs: Any) -> None: kwargs.pop('shard_id', None) self.shard_ids: Optional[List[int]] = kwargs.pop('shard_ids', None) + self.shard_connect_timeout: Optional[float] = kwargs.pop('shard_connect_timeout', 180.0) + super().__init__(*args, intents=intents, **kwargs) if self.shard_ids is not None: @@ -411,7 +418,7 @@ def shards(self) -> Dict[int, ShardInfo]: async def launch_shard(self, gateway: yarl.URL, shard_id: int, *, initial: bool = False) -> None: try: coro = DiscordWebSocket.from_client(self, initial=initial, gateway=gateway, shard_id=shard_id) - ws = await asyncio.wait_for(coro, timeout=180.0) + ws = await asyncio.wait_for(coro, timeout=self.shard_connect_timeout) except Exception: _log.exception('Failed to connect for shard_id: %s. Retrying...', shard_id) await asyncio.sleep(5.0)