aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2019-03-18 05:29:38 -0400
committerRapptz <[email protected]>2019-03-18 05:29:38 -0400
commit963cf4b34e1de5cba4879689894f6ccb84cf3d9f (patch)
treebd4fb32a226652540e81f23cbc9ddab79c422da6
parent[commands] Walk through MRO for Cog derived classes. (diff)
downloaddiscord.py-963cf4b34e1de5cba4879689894f6ccb84cf3d9f.tar.xz
discord.py-963cf4b34e1de5cba4879689894f6ccb84cf3d9f.zip
Add on_disconnect event.
I assume this is where it has to be. Fix #1937
-rw-r--r--discord/client.py1
-rw-r--r--docs/api.rst8
2 files changed, 9 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py
index 7f9e2c30..b8b4e051 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -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:
diff --git a/docs/api.rst b/docs/api.rst
index de55e6f5..0579cb79 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -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