diff options
| author | Rapptz <[email protected]> | 2020-05-10 19:30:46 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2020-05-10 19:35:45 -0400 |
| commit | 13a3f760e6de8aa251f06bbe2a746e5f92deafd2 (patch) | |
| tree | 697c61b86c7dc9ecd272a2de59aba5783eceb60a /discord/shard.py | |
| parent | allow passing color int to role.edit (diff) | |
| download | discord.py-13a3f760e6de8aa251f06bbe2a746e5f92deafd2.tar.xz discord.py-13a3f760e6de8aa251f06bbe2a746e5f92deafd2.zip | |
Fix timeout issues with fetching members via query_members
This uses the nonce field to properly disambiguate queries. There's
also some redesigning going on behind the scenes and minor clean-up.
Originally I planned on working on this more to account for the more
widespread chunking changes planned for gateway v7 but I realized that
this would indiscriminately slow down everyone else who isn't planning
on working with intents for now.
I will work on the larger chunking changes in the future, should time
allow for it.
Diffstat (limited to 'discord/shard.py')
| -rw-r--r-- | discord/shard.py | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/discord/shard.py b/discord/shard.py index e133cd0c..6d599dab 100644 --- a/discord/shard.py +++ b/discord/shard.py @@ -126,38 +126,19 @@ class AutoShardedClient(Client): elif not isinstance(self.shard_ids, (list, tuple)): raise ClientException('shard_ids parameter must be a list or a tuple.') - self._connection = AutoShardedConnectionState(dispatch=self.dispatch, chunker=self._chunker, + self._connection = AutoShardedConnectionState(dispatch=self.dispatch, handlers=self._handlers, syncer=self._syncer, http=self.http, loop=self.loop, **kwargs) # instead of a single websocket, we have multiple # the key is the shard_id self.shards = {} + self._connection._get_websocket = self._get_websocket - def _get_websocket(guild_id): - i = (guild_id >> 22) % self.shard_count - return self.shards[i].ws - - self._connection._get_websocket = _get_websocket - - async def _chunker(self, guild, *, shard_id=None): - try: - guild_id = guild.id - shard_id = shard_id or guild.shard_id - except AttributeError: - guild_id = [s.id for s in guild] - - payload = { - 'op': 8, - 'd': { - 'guild_id': guild_id, - 'query': '', - 'limit': 0 - } - } - - ws = self.shards[shard_id].ws - await ws.send_as_json(payload) + def _get_websocket(self, guild_id=None, *, shard_id=None): + if shard_id is None: + shard_id = (guild_id >> 22) % self.shard_count + return self.shards[shard_id].ws @property def latency(self): |