Closed Faf4a closed 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.
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.
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,
},
},
});
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.
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.
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:
Triggers: