Skip to content

Commit 79857b7

Browse files
Catalyst4222i0bsFayeDelpre-commit-ci[bot]
authored
feat: add the on_disconnect event (#1199)
* feat: add the `on_disconnect` event * Update docs/events.rst * refactor: Move on_disconnect call. (note, this is done without an IDE, pre-commit might fail) * ci: correct from checks. --------- Co-authored-by: Sophia <41456914+i0bs@users.noreply.github.com> Co-authored-by: DeltaX <33706469+DeltaXWizard@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e8075e4 commit 79857b7

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

docs/events.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ There are several different internal events:
5252

5353
- ``raw_socket_create``
5454
- ``on_start``
55+
- ``on_disconnect``
5556
- ``on_interaction``
5657
- ``on_command``
5758
- ``on_command_error``
@@ -82,6 +83,13 @@ This function takes no arguments.
8283
.. attention::
8384
Unlike ``on_ready``, this event will never be dispatched more than once.
8485

86+
Event: ``on_disconnect``
87+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
88+
This event fires whenever the connection is invalidated and will often precede an ``on_ready`` event
89+
90+
This function takes no arguments.
91+
92+
8593
Event: ``on_interaction``
8694
^^^^^^^^^^^^^^^^^^^^^^^^^^^
8795
This event fires on any interaction (commands, components, autocomplete and modals).

interactions/api/gateway/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,12 @@ async def _reconnect(self, to_resume: bool, code: Optional[int] = 1012) -> None:
929929
if self.__heartbeat_event.is_set():
930930
self.__heartbeat_event.clear() # Because we're hardresetting the process
931931

932+
self._dispatch.dispatch(
933+
"on_disconnect"
934+
) # will be followed by the on_ready event after reconnection
935+
# reconnection happens whenever it disconnects either with or without a resume prompt
936+
# as this is called whenever the WS client closes
937+
932938
if not to_resume:
933939
url = self.ws_url if self.ws_url else await self._http.get_gateway()
934940
else:

0 commit comments

Comments
 (0)