diff --git a/docs/api.rst b/docs/api.rst index c50098d9f..4700a3ba9 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -108,6 +108,9 @@ to handle it, which defaults to print a traceback and ignore the exception. .. warning:: 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() diff --git a/examples/background_task.py b/examples/background_task.py index 38dbf482a..c1e4c7e20 100644 --- a/examples/background_task.py +++ b/examples/background_task.py @@ -19,13 +19,5 @@ async def on_ready(): print(client.user.id) print('------') -loop = asyncio.get_event_loop() - -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() +client.loop.create_task(my_background_task()) +client.run('token')