Clarify on_ready
triggering more than twice.
On that note, fix the background_task example to use `Client.run` instead of manual loop management. That way the task will be cleaned up and cancelled inside `Client.run`.
This commit is contained in:
parent
a0f37f8e85
commit
d914c0a4e4
@ -108,6 +108,9 @@ to handle it, which defaults to print a traceback and ignore the exception.
|
|||||||
.. warning::
|
.. warning::
|
||||||
|
|
||||||
This function is not guaranteed to be the first event called.
|
This function is not guaranteed to be the first event called.
|
||||||
|
Likewise, this function is **not** guaranteed to only be called
|
||||||
|
once. This library implements reconnection logic and thus will
|
||||||
|
end up calling this event whenever a RESUME request fails.
|
||||||
|
|
||||||
.. function:: on_resumed()
|
.. function:: on_resumed()
|
||||||
|
|
||||||
|
@ -19,13 +19,5 @@ async def on_ready():
|
|||||||
print(client.user.id)
|
print(client.user.id)
|
||||||
print('------')
|
print('------')
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
client.loop.create_task(my_background_task())
|
||||||
|
client.run('token')
|
||||||
try:
|
|
||||||
loop.create_task(my_background_task())
|
|
||||||
loop.run_until_complete(client.login('token'))
|
|
||||||
loop.run_until_complete(client.connect())
|
|
||||||
except Exception:
|
|
||||||
loop.run_until_complete(client.close())
|
|
||||||
finally:
|
|
||||||
loop.close()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user