Tomato6966 / lavalink-client

Easy, flexible and feature-rich lavalink@v4 Client. Both for Beginners and Proficients.
https://tomato6966.github.io/lavalink-client/
MIT License
48 stars 13 forks source link

Undefined previous tracks #37

Closed Yanishamburger closed 2 months ago

Yanishamburger commented 2 months ago

Hello, how do I get the previous music because it gives me undefined when I go in the right path once the music skips.

I use player.queue.previous (it gives me the old skip music but when I want to play them again I cannot access the uri or the name because they are undefined)

Also i need help if you can tell me how to enable auto resume.

I use lavalink v4

Tomato6966 commented 2 months ago
const lastPlayedTrack = player.queue.previous[0];

await player.queue.add(lastPlayedTrack);  // to add to the pos in the queue 0 use: player.queue.splice(0, 0, lastPlayedTrack);
await player.skip();

or:

const lastPlayedTrack = player.queue.previous[0];
await player.play({ clientTrack: lastPlayedTrack });
Yanishamburger commented 2 months ago

Thank you, how can you activate auto recovery also please ?

Tomato6966 commented 2 months ago

what do you mean with "auto recovery"

you can provide the resume header on connect with the note, which then provides you the player data on the resumed event you can also provide a queuestore, to automatically store the queue remotely e.g. on redis or a database

Yanishamburger commented 2 months ago

Its auto resume, Do you have an example script to do this if it's not too much to ask? I'm not familiar with databases

Tomato6966 commented 2 months ago

I told you a way which doesn't need you to know databases.. you can also make it yourself by running a loop saving the player + queue data in a db and when yo uwant to call "autoresume" you create a player by the database data..

Yanishamburger commented 2 months ago

Sorry, I'm not English, I'm translating... So the answers are not exactly understandable to me. I should create an event for this or put it in the main file ?

And how to retrieve the header automatically?

Tomato6966 commented 2 months ago

https://lavalink.dev/api/index.html#resuming

or for more strict and manual playback control: on playerCreate create a interval, which saves the player data + player.queue in a database on "yourautoresume function" get the saved data(s) and create the player(s) with the queue

or

you can use ManagerOptions.queueOptions.queueStore to automatically store the queue externally.

to use resuming, you must do the following:

  1. node.updateSession(true, 60000) (enable resuming 'true' - allow it to keep playing while the bot is offline for 60000ms)
  2. save the current node.sessionId and then stop the player
  3. provide the sessionId in the nodeOptions while connecting (creating) the node nodes: [ {...nodeOptions, sessionId: "" }]
  4. if you provide the sessionId, there will be a following event triggered: node.on("resumed", (node, payload, allNodePlayersFetched) => { /* handle it*/ })
Yanishamburger commented 2 months ago

Ok thx very much, I wish you a good day/evening if I have any other questions I will get back to you thank you again. You are a great help.

Tomato6966 commented 2 months ago

your welcome, you can also check out my musicium repository, how i did the queue sync there... it's same "principle" but different way of music playback.. (not lavalink) so you'd need to adapt!