Overview
The Lavalink WebSocket API provides real-time bidirectional communication for player events, stats, and state updates. All WebSocket connections are established at/v4/websocket.
Connection Setup
Opening a Connection
Establish a WebSocket connection to:Required Headers
The password configured in your Lavalink server config
The user ID of your Discord bot
The name of your client in
NAME/VERSION format (e.g., lavalink-client/2.0.0)The session ID from a previous connection to resume that session
Example Connection Headers
Message Format
All WebSocket messages follow this standard format:The operation type identifying the message purpose
Additional fields specific to the operation type
OP Types
Ready OP
Dispatched when you successfully connect and authenticate with the Lavalink node.Always
"ready"Whether this connection resumed a previous session
The Lavalink session ID for this connection (not a Discord voice session ID)
Player Update OP
Dispatched at regular intervals (configurable inapplication.yml) with the current player state.
Always
"playerUpdate"The Discord guild ID of the player
The current player state
Stats OP
Dispatched once per minute with server statistics.Always
"stats"The number of players connected to the node
The number of players currently playing a track
The uptime of the node in milliseconds
Memory statistics for the node
CPU statistics for the node
Frame statistics (null if no players or when retrieved via
/v4/stats REST endpoint)Event OP
Dispatched when player or voice events occur.Always
"event"The event type. One of:
TrackStartEvent, TrackEndEvent, TrackExceptionEvent, TrackStuckEvent, WebSocketClosedEventThe Discord guild ID where the event occurred
Event Types
TrackStartEvent
Dispatched when a track starts playing.The track that started playing
TrackEndEvent
Dispatched when a track finishes playing or is stopped.The track that ended (same structure as TrackStartEvent)
The reason the track ended:
finished- The track completed normally (may start next: true)loadFailed- The track failed to load (may start next: true)stopped- The track was manually stopped (may start next: false)replaced- The track was replaced by another (may start next: false)cleanup- The track was cleaned up (may start next: false)
TrackExceptionEvent
Dispatched when a track throws an exception during playback.The track that threw the exception
The exception details
TrackStuckEvent
Dispatched when a track gets stuck while playing.The track that got stuck
The threshold in milliseconds that was exceeded
WebSocketClosedEvent
Dispatched when the Discord voice WebSocket connection closes. This can happen for various reasons. 4xxx codes typically indicate serious issues.The human-readable close reason
Whether the connection was closed by Discord (true) or locally (false)
For more information on Discord voice close codes, see the Discord Voice Close Event Codes documentation.