WebSocket API
Opening a connection
You can establish a WebSocket connection against the path /v4/websocket
.
When opening a websocket connection, you must supply 3 required headers:
*For more information on resuming see Resuming
Example Headers
Authorization: youshallnotpass
User-Id: 170939974227541168
Client-Name: lavalink-client/2.0.0
Websocket messages all follow the following standard format:
Example Payload
OP Types
Ready OP
Dispatched by Lavalink upon successful connection and authorization. Contains fields determining if resuming was successful, as well as the session id.
Example Payload
{
"op": "ready",
"resumed": false,
"sessionId": "..."
}
Player Update OP
Dispatched every x seconds (configurable in application.yml
) with the current state of the player.
Player State
Example Payload
{
"op": "playerUpdate",
"guildId": "...",
"state": {
"time": 1500467109,
"position": 60000,
"connected": true,
"ping": 50
}
}
Stats OP
A collection of statistics sent every minute.
Stats Object
Memory
CPU
Frame Stats
* The expected amount of frames is 3000 (1 every 20 ms) per player. If the deficit
is negative, too many frames were sent, and if it's positive, not enough frames got sent.
Example Payload
{
"op": "stats",
"players": 1,
"playingPlayers": 1,
"uptime": 123456789,
"memory": {
"free": 123456789,
"used": 123456789,
"allocated": 123456789,
"reservable": 123456789
},
"cpu": {
"cores": 4,
"systemLoad": 0.5,
"lavalinkLoad": 0.5
},
"frameStats": {
"sent": 6000,
"nulled": 10,
"deficit": -3010
}
}
Event OP
Server dispatched an event. See the Event Types section for more information.
Example Payload
{
"op": "event",
"type": "...",
"guildId": "...",
...
}
Event Types
TrackStartEvent
Dispatched when a track starts playing.
Example Payload
{
"op": "event",
"type": "TrackStartEvent",
"guildId": "...",
"track": {
"encoded": "QAAAjQIAJVJpY2sgQXN0bGV5IC0gTmV2ZXIgR29ubmEgR2l2ZSBZb3UgVXAADlJpY2tBc3RsZXlWRVZPAAAAAAADPCAAC2RRdzR3OVdnWGNRAAEAK2h0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9ZFF3NHc5V2dYY1EAB3lvdXR1YmUAAAAAAAAAAA==",
"info": {
"identifier": "dQw4w9WgXcQ",
"isSeekable": true,
"author": "RickAstleyVEVO",
"length": 212000,
"isStream": false,
"position": 0,
"title": "Rick Astley - Never Gonna Give You Up",
"uri": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"artworkUrl": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
"isrc": null,
"sourceName": "youtube"
},
"pluginInfo": {}
}
}
TrackEndEvent
Dispatched when a track ends.
Track End Reason
Example Payload
{
"op": "event",
"type": "TrackEndEvent",
"guildId": "...",
"track": {
"encoded": "QAAAjQIAJVJpY2sgQXN0bGV5IC0gTmV2ZXIgR29ubmEgR2l2ZSBZb3UgVXAADlJpY2tBc3RsZXlWRVZPAAAAAAADPCAAC2RRdzR3OVdnWGNRAAEAK2h0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9ZFF3NHc5V2dYY1EAB3lvdXR1YmUAAAAAAAAAAA==",
"info": {
"identifier": "dQw4w9WgXcQ",
"isSeekable": true,
"author": "RickAstleyVEVO",
"length": 212000,
"isStream": false,
"position": 0,
"title": "Rick Astley - Never Gonna Give You Up",
"uri": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"artworkUrl": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
"isrc": null,
"sourceName": "youtube"
},
"pluginInfo": {}
},
"reason": "finished"
}
TrackExceptionEvent
Dispatched when a track throws an exception.
Exception Object
Severity
Example Payload
{
"op": "event",
"type": "TrackExceptionEvent",
"guildId": "...",
"track": {
"encoded": "QAAAjQIAJVJpY2sgQXN0bGV5IC0gTmV2ZXIgR29ubmEgR2l2ZSBZb3UgVXAADlJpY2tBc3RsZXlWRVZPAAAAAAADPCAAC2RRdzR3OVdnWGNRAAEAK2h0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9ZFF3NHc5V2dYY1EAB3lvdXR1YmUAAAAAAAAAAA==",
"info": {
"identifier": "dQw4w9WgXcQ",
"isSeekable": true,
"author": "RickAstleyVEVO",
"length": 212000,
"isStream": false,
"position": 0,
"title": "Rick Astley - Never Gonna Give You Up",
"uri": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"artworkUrl": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
"isrc": null,
"sourceName": "youtube"
},
"pluginInfo": {}
},
"exception": {
"message": "...",
"severity": "common",
"cause": "..."
}
}
TrackStuckEvent
Dispatched when a track gets stuck while playing.
Example Payload
{
"op": "event",
"type": "TrackStuckEvent",
"guildId": "...",
"track": {
"encoded": "QAAAjQIAJVJpY2sgQXN0bGV5IC0gTmV2ZXIgR29ubmEgR2l2ZSBZb3UgVXAADlJpY2tBc3RsZXlWRVZPAAAAAAADPCAAC2RRdzR3OVdnWGNRAAEAK2h0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9ZFF3NHc5V2dYY1EAB3lvdXR1YmUAAAAAAAAAAA==",
"info": {
"identifier": "dQw4w9WgXcQ",
"isSeekable": true,
"author": "RickAstleyVEVO",
"length": 212000,
"isStream": false,
"position": 0,
"title": "Rick Astley - Never Gonna Give You Up",
"uri": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"artworkUrl": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
"isrc": null,
"sourceName": "youtube"
},
"pluginInfo": {}
},
"thresholdMs": 123456789
}
WebSocketClosedEvent
Dispatched when an audio WebSocket (to Discord) is closed.
This can happen for various reasons (normal and abnormal), e.g. when using an expired voice server update.
4xxx codes are usually bad.
See the Discord Docs.
Example Payload
{
"op": "event",
"type": "WebSocketClosedEvent",
"guildId": "...",
"code": 4006,
"reason": "Your session is no longer valid.",
"byRemote": true
}