diff --git a/wavelink/payloads.py b/wavelink/payloads.py index 6d44bd2e..1dbffdd3 100644 --- a/wavelink/payloads.py +++ b/wavelink/payloads.py @@ -53,6 +53,7 @@ "PlayerUpdateEventPayload", "StatsEventPayload", "NodeReadyEventPayload", + "NodeDisconnectedEventPayload", "StatsEventMemory", "StatsEventCPU", "StatsEventFrames", @@ -87,6 +88,19 @@ def __init__(self, node: Node, resumed: bool, session_id: str) -> None: self.session_id = session_id +class NodeDisconnectedEventPayload: + """Payload received in the :func:`on_wavelink_node_disconnected` event. + + Attributes + ---------- + node: :class:`~wavelink.Node` + The node that has disconnected. + """ + + def __init__(self, node: Node) -> None: + self.node = node + + class TrackStartEventPayload: """Payload received in the :func:`on_wavelink_track_start` event. diff --git a/wavelink/websocket.py b/wavelink/websocket.py index 18c5befa..422bb42f 100644 --- a/wavelink/websocket.py +++ b/wavelink/websocket.py @@ -88,6 +88,12 @@ async def _update_node(self) -> None: self.node._spotify_enabled = True async def connect(self) -> None: + if self.node._status is NodeStatus.CONNECTED: + # Node was previously connected... + # We can dispatch an event to say the node was disconnected... + payload: NodeDisconnectedEventPayload = NodeDisconnectedEventPayload(node=self.node) + self.dispatch("node_disconnected", payload) + self.node._status = NodeStatus.CONNECTING if self.keep_alive_task: @@ -283,4 +289,7 @@ async def cleanup(self) -> None: self.node._websocket = None + payload: NodeDisconnectedEventPayload = NodeDisconnectedEventPayload(node=self.node) + self.dispatch("node_disconnected", payload) + logger.debug("Successfully cleaned up the websocket for %r", self.node)