mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-18 23:15:48 +00:00
Re-add Client.wait_until_ready
This commit is contained in:
parent
b27fab09eb
commit
8c896e9fbc
@ -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|
|
||||
|
||||
|
@ -15,7 +15,7 @@ class MyClient(discord.Client):
|
||||
print('------')
|
||||
|
||||
async def my_background_task(self):
|
||||
await self.wait_for('ready')
|
||||
await self.wait_until_ready()
|
||||
counter = 0
|
||||
channel = self.get_channel(1234567) # channel ID goes here
|
||||
while not self.is_closed:
|
||||
|
Loading…
x
Reference in New Issue
Block a user