Add on_disconnect event.

I assume this is where it has to be. Fix #1937
This commit is contained in:
Rapptz 2019-03-18 05:29:38 -04:00
parent f43690bde8
commit 963cf4b34e
2 changed files with 9 additions and 0 deletions

View File

@ -409,6 +409,7 @@ class Client:
websockets.InvalidHandshake,
websockets.WebSocketProtocolError) as exc:
self.dispatch('disconnect')
if not reconnect:
await self.close()
if isinstance(exc, ConnectionClosed) and exc.code == 1000:

View File

@ -103,6 +103,14 @@ to handle it, which defaults to print a traceback and ignoring the exception.
The warnings on :func:`on_ready` also apply.
.. function:: on_disconnect()
Called when the client has disconnected from Discord. This could happen either through
the internet being disconnect, explicit calls to logout, or Discord terminating the connection
one way or the other.
This function can be called many times.
.. function:: on_ready()
Called when the client is done preparing the data received from Discord. Usually after login is successful