aboutsummaryrefslogtreecommitdiff
path: root/discord/state.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2020-05-24 08:34:35 -0400
committerRapptz <[email protected]>2020-07-25 09:59:40 -0400
commitd37b91dfc66c14ee29a334337b8cf63f974d6c4a (patch)
treea712e7b9019005ec89e09f3b6b5aec80bd9b2748 /discord/state.py
parentAdd a timeout for receiving websocket messages. (diff)
downloaddiscord.py-d37b91dfc66c14ee29a334337b8cf63f974d6c4a.tar.xz
discord.py-d37b91dfc66c14ee29a334337b8cf63f974d6c4a.zip
Add guild_ready_timeout to control the timeout of GUILD_CREATE stream
This also fixes a timing issue where READY would take far too long to load for big bot authors. Closes #4112
Diffstat (limited to 'discord/state.py')
-rw-r--r--discord/state.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/discord/state.py b/discord/state.py
index 10403032..34823845 100644
--- a/discord/state.py
+++ b/discord/state.py
@@ -80,6 +80,10 @@ class ConnectionState:
self._ready_task = None
self._fetch_offline = options.get('fetch_offline_members', True)
self.heartbeat_timeout = options.get('heartbeat_timeout', 60.0)
+ self.guild_ready_timeout = options.get('guild_ready_timeout', 2.0)
+ if self.guild_ready_timeout < 0:
+ raise ValueError('guild_ready_timeout cannot be negative')
+
self.guild_subscriptions = options.get('guild_subscriptions', True)
allowed_mentions = options.get('allowed_mentions')
@@ -369,10 +373,10 @@ class ConnectionState:
# only real bots wait for GUILD_CREATE streaming
if self.is_bot:
while True:
- # this snippet of code is basically waiting 2 seconds
+ # this snippet of code is basically waiting N seconds
# until the last GUILD_CREATE was sent
try:
- await asyncio.wait_for(launch.wait(), timeout=2.0)
+ await asyncio.wait_for(launch.wait(), timeout=self.guild_ready_timeout)
except asyncio.TimeoutError:
break
else:
@@ -1086,10 +1090,10 @@ class AutoShardedConnectionState(ConnectionState):
await self.shards_launched.wait()
launch = self._ready_state.launch
while True:
- # this snippet of code is basically waiting 2 * shard_ids seconds
+ # this snippet of code is basically waiting N seconds
# until the last GUILD_CREATE was sent
try:
- await asyncio.wait_for(launch.wait(), timeout=2.0 * len(self.shard_ids))
+ await asyncio.wait_for(launch.wait(), timeout=self.guild_ready_timeout)
except asyncio.TimeoutError:
break
else: