Restarts without silence
Lavalink plays the audio, not your bot. If Raya closes its connection the right way, Lavalink keeps every player going for resumeTimeout seconds (60 by default). The next process picks them up again.
-
Before exiting, take a snapshot.
shutdown()waits for pending updates, saves every player, and closes node connections without destroying players.const fs = require('node:fs');async function shutdown() {const snapshot = await raya.shutdown();fs.writeFileSync('raya-snapshot.json', JSON.stringify(snapshot));await client.destroy();process.exit(0);}process.on('SIGINT', shutdown);process.on('SIGTERM', shutdown); -
On start, read the snapshot once and pass it as
restore:let restore;if (fs.existsSync('raya-snapshot.json')) {restore = JSON.parse(fs.readFileSync('raya-snapshot.json', 'utf8'));fs.unlinkSync('raya-snapshot.json'); // snapshots are single use}const raya = new Raya({ nodes, connector, restore }); -
That’s it. Raya reconnects with the saved session id. Lavalink reports the session as resumed, and every player is restored with its queue, requesters, loop mode, filters, volume and
player.data.
raya.on('playerResume', (player) => console.log(`Restored ${player.guildId}`));What gets saved
Section titled “What gets saved”- Current track (with requester) and position
- Queue and history
- Volume, paused, loop, autoplay and filters
- Voice and text channels, self deaf and mute
player.dataentries- The Lavalink session id of each node
If the restart takes too long
Section titled “If the restart takes too long”If the session expired before the new process connected, Raya rebuilds each player from the snapshot instead. It rejoins the voice channel and starts the track at the saved position. You’ll hear a short gap, but nothing is lost.
Crash protection
Section titled “Crash protection”raya.snapshot() returns the same data without closing anything. Save it every so often (for example on queueUpdate, throttled) so a crash loses at most a few seconds:
- If the new process starts within
resumeTimeout, the Lavalink session still resumes, and Raya takes the live track and position from Lavalink. - If not, players are rebuilt from the last snapshot.