From 3db4ce5fe2eaaf1fb0dc9692217f7682887d38f1 Mon Sep 17 00:00:00 2001 From: "Chrissy8283 (aka Tomato6966)" Date: Mon, 1 Jul 2024 20:18:37 +0200 Subject: [PATCH] Add resuming sample --- README.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b97aa11..56f7412 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,31 @@ client.lavalink = new LavalinkManager({ }) ``` +## How to do resuming + +```js +// 1. while the player is playing, make sure to enable it: +const durationToKeepPlayingInMS = 600_000; +await player.node.updateSession(true, durationToKeepPlayingInMS); +``` + +```js +// 2. make sure to have an eventlistener for resuming events somewhere +client.lavalink.nodeManager.on("resumed", (node, payload, fetchedPlayers) => { + // create players: + for(const fetchedPlayer of fetchedPlayers) { + const player = client.lavalink.createPlayer({ + guildId: fetchedPlayer.guildId, + }); + player.setVolume(fetchedPlayer.volume); + // and apply other things (e.g. paused, voice, filters, state, ...) (stuff like vc channel, text channel you need to store somewhere) + await player.queue.utils.sync(); // only works with a queuestore + // you can now overwride the player.queue.current track from the fetchedPlayer, or use the one from the queue.uztils.sync function + // continue with your resuming code... + } +}) +``` + *** # UpdateLog @@ -241,7 +266,7 @@ client.lavalink = new LavalinkManager({ # Node Resuming got supported # First enable it by doing: -+ await player.node.updateResuming(true, 360_000); ++ await player.node.updateSession(true, 360_000); # then when reconnecting to the node add to the node.createeOptions the sessionId: "" of the previous session # and after connecting the nodeManager.on("resumed", (node, payload, players) => {}) will be executed, where you can sync the players!