From 1c7b3a01c20cabbfb8ced64d9c20860637c664d7 Mon Sep 17 00:00:00 2001 From: Angelo Breuer Date: Fri, 22 Sep 2023 11:55:32 +0200 Subject: [PATCH] fix: Fix issue when player is moved to a new voice channel --- src/Lavalink4NET/Players/LavalinkPlayer.cs | 23 +++++++--------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/Lavalink4NET/Players/LavalinkPlayer.cs b/src/Lavalink4NET/Players/LavalinkPlayer.cs index b4b704ad..9a963ca0 100644 --- a/src/Lavalink4NET/Players/LavalinkPlayer.cs +++ b/src/Lavalink4NET/Players/LavalinkPlayer.cs @@ -140,19 +140,7 @@ async ValueTask ILavalinkPlayerListener.NotifyChannelUpdateAsync(ulong? voiceCha _logger.PlayerMoved(Label, voiceChannelId); } - VoiceChannelId = voiceChannelId.Value; - - try - { - await NotifyChannelUpdateAsync(voiceChannelId, cancellationToken).ConfigureAwait(false); - } - finally - { - if (_disconnectOnDestroy && voiceChannelId is null) - { - await DisposeAsync().ConfigureAwait(false); - } - } + await NotifyChannelUpdateAsync(voiceChannelId, cancellationToken).ConfigureAwait(false); } async ValueTask ILavalinkPlayerListener.NotifyTrackEndedAsync(LavalinkTrack track, TrackEndReason endReason, CancellationToken cancellationToken) @@ -333,9 +321,6 @@ async ValueTask ILavalinkPlayerListener.NotifyWebSocketClosedAsync(WebSocketClos { cancellationToken.ThrowIfCancellationRequested(); - VoiceServer = null; - VoiceState = new VoiceState(VoiceState.VoiceChannelId, SessionId: null); - await NotifyWebSocketClosedAsync(closeStatus, reason, byRemote, cancellationToken).ConfigureAwait(false); } @@ -543,6 +528,12 @@ await _playerLifecycle protected virtual ValueTask NotifyVoiceStateUpdatedAsync(VoiceState voiceState, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); + + if (VoiceState.VoiceChannelId != VoiceChannelId) + { + VoiceServer = null; + } + VoiceState = voiceState; if (voiceState.VoiceChannelId is null)