Skip to content

Commit

Permalink
Add shard_connect_timeout parameter for AutoShardedClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapptz committed Jan 8, 2024
1 parent 9a1b91d commit cb3ea9b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion discord/shard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cb3ea9b

Please sign in to comment.