From 5261748d55b90f820b6e06021f70757f461743dd Mon Sep 17 00:00:00 2001 From: upo <> Date: Sat, 15 Jun 2024 23:52:49 +0200 Subject: [PATCH 1/2] A toggle for clearing the queue after the bot has left the channel In Lavalink 4.X.X the queue is managed by Lavalink itself, and becuase of that, the tracks in the queue persist even after the bot leaves the channel, and they stay there until Lavalink is restarted. I found this a little bit annoying at times, so I added a toggle in the config for whether or not the queue should be cleared upon calling Lavanode.LeaveAsync() --- src/Configuration.cs | 8 +++++++- src/LavaNode.cs | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Configuration.cs b/src/Configuration.cs index 71f80e6..1faf736 100644 --- a/src/Configuration.cs +++ b/src/Configuration.cs @@ -1,4 +1,4 @@ -using System; +using System; using Victoria.WebSocket.Internal; namespace Victoria; @@ -54,6 +54,12 @@ public record Configuration { public bool SelfDeaf { get; set; } = true; + /// + /// Whether to preserve the queue of a guild after the bot has left the channel (note that the queue will only be preserved until lavalink is restarted). + /// + public bool PreserveQueue { get; set; } + = false; + /// /// /// diff --git a/src/LavaNode.cs b/src/LavaNode.cs index 8c575ca..c60110e 100644 --- a/src/LavaNode.cs +++ b/src/LavaNode.cs @@ -222,6 +222,10 @@ public async Task LeaveAsync(IVoiceChannel voiceChannel) { ArgumentNullException.ThrowIfNull(voiceChannel); await voiceChannel.DisconnectAsync() .ConfigureAwait(false); + + if (!this._configuration.PreserveQueue) + (GetPlayerAsync(voiceChannel.GuildId).Result as LavaPlayer).GetQueue().Clear(); + await DestroyPlayerAsync(voiceChannel.GuildId); } From d07b71c643d93440454187945263e3d8232c7eb2 Mon Sep 17 00:00:00 2001 From: upo <> Date: Mon, 17 Jun 2024 15:10:47 +0200 Subject: [PATCH 2/2] Changed it accordingly with PR suggestion It just clears the queue now --- src/Configuration.cs | 6 ------ src/LavaNode.cs | 5 +---- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Configuration.cs b/src/Configuration.cs index 1faf736..652d4f4 100644 --- a/src/Configuration.cs +++ b/src/Configuration.cs @@ -54,12 +54,6 @@ public record Configuration { public bool SelfDeaf { get; set; } = true; - /// - /// Whether to preserve the queue of a guild after the bot has left the channel (note that the queue will only be preserved until lavalink is restarted). - /// - public bool PreserveQueue { get; set; } - = false; - /// /// /// diff --git a/src/LavaNode.cs b/src/LavaNode.cs index c60110e..d23dc77 100644 --- a/src/LavaNode.cs +++ b/src/LavaNode.cs @@ -222,10 +222,7 @@ public async Task LeaveAsync(IVoiceChannel voiceChannel) { ArgumentNullException.ThrowIfNull(voiceChannel); await voiceChannel.DisconnectAsync() .ConfigureAwait(false); - - if (!this._configuration.PreserveQueue) - (GetPlayerAsync(voiceChannel.GuildId).Result as LavaPlayer).GetQueue().Clear(); - + LavaPlayerExtensions.Queue?.TryRemove(voiceChannel.GuildId, out _); await DestroyPlayerAsync(voiceChannel.GuildId); }