Skip to content

Commit 2448567

Browse files
authored
feat: on_start event (#927)
* feat: add on_start event * docs: document the event
1 parent 044813d commit 2448567

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

docs/events.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ All events mentioned in this section have the exact naming as they must be put i
5151
There are several different internal events:
5252

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

7273

74+
Event: ``on_start``
75+
^^^^^^^^^^^^^^^^^^^
76+
This event fires only when the bot is started.
77+
78+
This function takes no arguments.
79+
80+
.. attention::
81+
Unlike ``on_ready``, this event will never be dispatched more than once.
82+
7383
Event: ``on_interaction``
7484
^^^^^^^^^^^^^^^^^^^^^^^^^^
7585
This event fires on any interaction (commands, components, autocomplete and modals).

interactions/api/gateway/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class WebSocketClient:
8080
"__shard",
8181
"__presence",
8282
"__task",
83+
"__started",
8384
"session_id",
8485
"sequence",
8586
"ready",
@@ -126,6 +127,7 @@ def __init__(
126127
self.__shard: Optional[List[Tuple[int]]] = None
127128
self.__presence: Optional[ClientPresence] = None
128129
self.__task: Optional[Task] = None
130+
self.__started: bool = False
129131
self.session_id: Optional[str] = None if session_id is MISSING else session_id
130132
self.sequence: Optional[str] = None if sequence is MISSING else sequence
131133
self.ready: Event = Event(loop=self._loop) if version_info < (3, 10) else Event()
@@ -258,6 +260,9 @@ async def _handle_connection(
258260
self.session_id = data["session_id"]
259261
self.sequence = stream["s"]
260262
self._dispatch.dispatch("on_ready")
263+
if not self.__started:
264+
self.__started = True
265+
self._dispatch.dispatch("on_start")
261266
log.debug(f"READY (session_id: {self.session_id}, seq: {self.sequence})")
262267
self.ready.set()
263268
else:

0 commit comments

Comments
 (0)