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

autoPlayFunction not triggering #21

Closed Faf4a closed 6 months ago

Faf4a commented 6 months ago

Small question, is autoPlayFunction not supposed to trigger when only one song is added, meaning there would be no queue and only the current playing song?

Or could it be that I'm doing something wrong, because when I add two songs (current, and one to queue) it triggers after the second song finishes playing.

For better understanding:

Doesn't trigger:

Queue {
  tracks: [],
  previous: [],
  current: [Object],
  options: [Object],
  guildId: 'some guild id',
  QueueSaver: [QueueSaver],
  managerUtils: [ManagerUtils],
  queueChanges: null,
  utils: [Object]
}

Triggers:

Queue {
  tracks: [],
  previous: [Array],
  current: [Object],
  options: [Object],
  guildId: 'some guild id',
  QueueSaver: [QueueSaver],
  managerUtils: [ManagerUtils],
  queueChanges: null,
  utils: [Object]
}
Faf4a commented 6 months ago

However this works,

    manager.on("queueEnd", async (player) => {
      if (player.get("autoplay") === false) return;
      await autoPlayFunction(player, player.queue.previous[0]);
    });

Regardless on queue length.

Tomato6966 commented 6 months ago

It triggers AUTOMATICALLY (when provided to the manageroptions), you don't have to call the function by yourself. It triggers when no songs are in the queue and the current song ends.

Tomato6966 commented 6 months ago

As you can see in the examplebot: https://github.com/Tomato6966/lavalink-client/blob/main/testBot/index.ts#L72 this is how you provide it

async function autoPlayFunction(player, lastPlayedTrack) {
 if(player.get("autoplay") === false) return;
 // somehow get the next song
 await player.queue.add(nextSong); //if the await of the function is done, and there is no more song in player.queue.tracks then it will emit queueEnd, else it will play it!
// so all you need to do is in that function, decide wether to add a track or not. also it's your choice how many tracks you want to add
}
client.lavalink = new LavalinkManager({
    // ....
    playerOptions: {
        onEmptyQueue: {
            autoPlayFunction: autoPlayFunction,
        },
    },
});
Tomato6966 commented 6 months ago

You can see in the source code how that works https://github.com/Tomato6966/lavalink-client/blob/main/src/structures/Node.ts#L915

If you want to make a autoplayfunction all by yourself, you can do that too, but that's not client issue then.

Faf4a commented 6 months ago

You can see in the source code how that works https://github.com/Tomato6966/lavalink-client/blob/main/src/structures/Node.ts#L915

Thanks for the heads up, seems to work now.

No idea what caused, well whatever it works now.