Documentation Index
Fetch the complete documentation index at: https://mintlify.com/lavalink-devs/Lavalink/llms.txt
Use this file to discover all available pages before exploring further.
Required Discord Library Capabilities
Before implementing a Lavalink client, ensure your Discord library supports these essential features:Gateway Message Sending
Gateway Message Sending
You must be able to send messages via a shard’s gateway connection to initiate voice connections.
Voice Event Interception
Voice Event Interception
You must be able to intercept and handle these Discord events on your shard connection:
VOICE_SERVER_UPDATE- Provides connection endpoint and tokenVOICE_STATE_UPDATE- Provides session ID and channel information
Connection Flow
Establish WebSocket Connection
Connect to Lavalink’s WebSocket endpoint at
/v4/websocket with required headers:Receive Ready Event
Wait for the Store the
ready op to confirm connection and get your session ID:sessionId - you’ll need it for REST API calls and resuming.Intercept Discord Voice Events
Capture the voice server update and voice state update from Discord:Voice Server Update:Voice State Update:You need:
token, endpoint, session_id, and channel_id.Resuming Sessions
Resuming allows you to reconnect to Lavalink without interrupting playback.How Resuming Works
When resuming is disabled:- All voice connections close immediately on disconnect
- All player state is lost
- Music continues playing during disconnection
- Events are queued and replayed upon reconnection
- You can resume control of existing players
Enable Resuming
Common Pitfalls
1. Not Forwarding Voice Events to Lavalink
Problem: You must interceptVOICE_SERVER_UPDATE and VOICE_STATE_UPDATE events and send them to Lavalink.
Solution: Extract endpoint, token, and session_id from Discord events and forward them via the Update Player endpoint.
2. Not Joining a Voice Channel Before Playing
Problem: Attempting to play audio without first establishing a voice connection. Solution: Always join a voice channel before loading tracks:- Send Discord voice state update (op 4)
- Wait for voice events from Discord
- Forward to Lavalink
- Load and play tracks
3. Creating Voice Connections with Discord Library
Problem: Trying to manage voice connections directly with your Discord library while using Lavalink. Solution: Let Lavalink handle all voice connection logic. Your Discord library should only:- Send the initial voice state update (op 4)
- Forward voice events to Lavalink
- Not create its own voice connections
4. Ignoring Debug Logs
Problem: Not checking Lavalink server logs when issues occur. Solution: Check/logs/debug.log on your Lavalink server for detailed error information.
Handling Lavalink Server Crashes
If the Lavalink server suddenly dies, send this event to Discord to disconnect from voice channels:Shard Connection Dependencies
Maintain a stable Discord gateway connection to ensure uninterrupted audio playback.Event Handling
Listen for WebSocket events to respond to player state changes:Search Functionality
Lavalink supports searching on multiple platforms:Search prefixes only work if the corresponding source managers are enabled on the Lavalink server.
Best Practices
Session Management
Enable resuming for production bots to handle reconnections gracefully
Error Handling
Always handle
TrackExceptionEvent and WebSocketClosedEventState Tracking
Store session IDs and player state for crash recovery
Event Queuing
Implement a queue system for track management based on
TrackEndEventNext Steps
Authentication
Secure your Lavalink connection
REST API
Full REST API reference
WebSocket API
Complete WebSocket documentation
Filters
Audio effects and filters