Session resumption
Lavalink can keep a session alive for a configurable window after your bot disconnects. If you reconnect within that window and present the original session ID, Lavalink resumes — queues keep playing, no interruption.
Discolink doesn’t implement this automatically. The right approach depends on your scale and persistence layer.
-
Opt in and persist the session ID
On a fresh connection, tell Lavalink to keep the session alive and store the session ID:
player.on("nodeReady", async (node, resumed) => {if (!resumed) {// Enable resumption with a 60-second windowawait node.rest.updateSession({ resuming: true, timeout: 60 });// Persist the session ID — use your preferred storageawait db.set(`session:${node.name}`, node.sessionId);}}); -
Pass the session ID on reconnect
Disable auto init and initialize nodes with their session IDs:
const player = new Player({autoInit: false,// don't pass your nodes here anymore// ...});// Retrieve the stored session ID, then initializeconst storedSessionId = await db.get("session:main");await player.init(clientId, [{name: "main",origin: "http://localhost:2333",password: "youshallnotpass",sessionId: storedSessionId ?? undefined,},]); -
Sync local state after a successful resume
After a node reconnects, update your queues:
player.on("nodeReady", async (node, resumed) => {if (!resumed) {// Clear data associated with the nodeawait db.del(`session:${node.name}`);await db.del(`queues:${node.name}`);return;}// Re-create queues from saved dataconst queues = await db.get(`queues:${node.name}`);for (const q of unpackQueues(queues)) await player.queues.create(q);// Note: syncing does not add a (current) track// Note: if there are too many queues, sync them individually not in bulkawait player.queues.sync(node);});
