Skip to content

Commit 71d1385

Browse files
authored
feat: ability to define which shards connect (#1602)
* feat: ability to define which shards connect * refactor: AutoShardedClient's only_shards to shard_ids
1 parent e52af6c commit 71d1385

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

interactions/client/auto_shard_client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import time
33
from datetime import datetime
44
from collections import defaultdict
5-
from typing import TYPE_CHECKING, Optional
5+
from typing import TYPE_CHECKING, Optional, List
66

77
import interactions.api.events as events
88
from interactions.api.events import ShardConnect
@@ -35,6 +35,8 @@ def __init__(self, *args, **kwargs) -> None:
3535
self.auto_sharding = "total_shards" not in kwargs
3636
super().__init__(*args, **kwargs)
3737

38+
self.shard_ids: Optional[List[int]] = kwargs.get("shard_ids", None)
39+
3840
self._connection_state = None
3941

4042
self._connection_states: list[ConnectionState] = []
@@ -244,9 +246,13 @@ async def login(self, token: str | None = None) -> None:
244246
)
245247

246248
self.logger.debug(f"Starting bot with {self.total_shards} shard{'s' if self.total_shards != 1 else ''}")
247-
self._connection_states: list[ConnectionState] = [
248-
ConnectionState(self, self.intents, shard_id) for shard_id in range(self.total_shards)
249-
]
249+
250+
if self.shard_ids:
251+
self._connection_states = [ConnectionState(self, self.intents, shard_id) for shard_id in self.shard_ids]
252+
else:
253+
self._connection_states = [
254+
ConnectionState(self, self.intents, shard_id) for shard_id in range(self.total_shards)
255+
]
250256

251257
async def change_presence(
252258
self,

0 commit comments

Comments
 (0)