aboutsummaryrefslogtreecommitdiff
path: root/discord/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'discord/client.py')
-rw-r--r--discord/client.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py
index 76509016..2e99b102 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -120,6 +120,7 @@ class Client:
self.connection.shard_count = self.shard_count
self._closed = asyncio.Event(loop=self.loop)
+ self._ready = asyncio.Event(loop=self.loop)
# if VoiceClient.warn_nacl:
# VoiceClient.warn_nacl = False
@@ -149,6 +150,9 @@ class Client:
yield from self.ws.send_as_json(payload)
+ def handle_ready(self):
+ self._ready.set()
+
def _resolve_invite(self, invite):
if isinstance(invite, Invite) or isinstance(invite, Object):
return invite.id
@@ -189,6 +193,11 @@ class Client:
"""List[:class:`VoiceClient`]: Represents a list of voice connections."""
return self.connection.voice_clients
+ @property
+ def is_ready(self):
+ """bool: Specifies if the client's internal cache is ready for use."""
+ return self._ready.is_set()
+
@asyncio.coroutine
def _run_event(self, coro, event_name, *args, **kwargs):
try:
@@ -356,6 +365,10 @@ class Client:
except (ReconnectWebSocket, ResumeWebSocket) as e:
resume = type(e) is ResumeWebSocket
log.info('Got ' + type(e).__name__)
+
+ if not resume:
+ self._ready.clear()
+
self.ws = yield from DiscordWebSocket.from_client(self, shard_id=self.shard_id,
session=self.ws.session_id,
sequence=self.ws.sequence,
@@ -389,6 +402,7 @@ class Client:
yield from self.http.close()
self._closed.set()
+ self._ready.clear()
@asyncio.coroutine
def start(self, *args, **kwargs):
@@ -513,6 +527,14 @@ class Client:
# listeners/waiters
+ @asyncio.coroutine
+ def wait_until_ready(self):
+ """|coro|
+
+ Waits until the client's internal cache is all ready.
+ """
+ yield from self._ready.wait()
+
def wait_for(self, event, *, check=None, timeout=None):
"""|coro|