Skip to content

Commit 3db4ce5

Browse files
authored
Add resuming sample
1 parent 5648cc5 commit 3db4ce5

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,31 @@ client.lavalink = new LavalinkManager({
185185
})
186186
```
187187
188+
## How to do resuming
189+
190+
```js
191+
// 1. while the player is playing, make sure to enable it:
192+
const durationToKeepPlayingInMS = 600_000;
193+
await player.node.updateSession(true, durationToKeepPlayingInMS);
194+
```
195+
196+
```js
197+
// 2. make sure to have an eventlistener for resuming events somewhere
198+
client.lavalink.nodeManager.on("resumed", (node, payload, fetchedPlayers) => {
199+
// create players:
200+
for(const fetchedPlayer of fetchedPlayers) {
201+
const player = client.lavalink.createPlayer({
202+
guildId: fetchedPlayer.guildId,
203+
});
204+
player.setVolume(fetchedPlayer.volume);
205+
// and apply other things (e.g. paused, voice, filters, state, ...) (stuff like vc channel, text channel you need to store somewhere)
206+
await player.queue.utils.sync(); // only works with a queuestore
207+
// you can now overwride the player.queue.current track from the fetchedPlayer, or use the one from the queue.uztils.sync function
208+
// continue with your resuming code...
209+
}
210+
})
211+
```
212+
188213
***
189214
190215
# UpdateLog
@@ -241,7 +266,7 @@ client.lavalink = new LavalinkManager({
241266
242267
# Node Resuming got supported
243268
# First enable it by doing:
244-
+ await player.node.updateResuming(true, 360_000);
269+
+ await player.node.updateSession(true, 360_000);
245270
# then when reconnecting to the node add to the node.createeOptions the sessionId: "" of the previous session
246271
# and after connecting the nodeManager.on("resumed", (node, payload, players) => {}) will be executed, where you can sync the players!
247272

0 commit comments

Comments
 (0)