Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ All events mentioned in this section have the exact naming as they must be put i
There are several different internal events:

- ``raw_socket_create``
- ``on_start``
- ``on_interaction``
- ``on_command``
- ``on_component``
Expand All @@ -70,6 +71,15 @@ The value of the argument will be the *raw* data sent from Discord, so it is not
as long as you don't absolutely need it.


Event: ``on_start``
^^^^^^^^^^^^^^^^^^^
This event fires only when the bot is started.

This function takes no arguments.

.. attention::
Unlike ``on_ready``, this event will never be dispatched more than once.

Event: ``on_interaction``
^^^^^^^^^^^^^^^^^^^^^^^^^^
This event fires on any interaction (commands, components, autocomplete and modals).
Expand Down
5 changes: 5 additions & 0 deletions interactions/api/gateway/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class WebSocketClient:
"__shard",
"__presence",
"__task",
"__started",
"session_id",
"sequence",
"ready",
Expand Down Expand Up @@ -126,6 +127,7 @@ def __init__(
self.__shard: Optional[List[Tuple[int]]] = None
self.__presence: Optional[ClientPresence] = None
self.__task: Optional[Task] = None
self.__started: bool = False
self.session_id: Optional[str] = None if session_id is MISSING else session_id
self.sequence: Optional[str] = None if sequence is MISSING else sequence
self.ready: Event = Event(loop=self._loop) if version_info < (3, 10) else Event()
Expand Down Expand Up @@ -258,6 +260,9 @@ async def _handle_connection(
self.session_id = data["session_id"]
self.sequence = stream["s"]
self._dispatch.dispatch("on_ready")
if not self.__started:
self.__started = True
self._dispatch.dispatch("on_start")
log.debug(f"READY (session_id: {self.session_id}, seq: {self.sequence})")
self.ready.set()
else:
Expand Down