Skip to content

Commit

Permalink
fix: Fix issue when player is moved to a new voice channel
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Sep 22, 2023
1 parent 739ad55 commit 1c7b3a0
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/Lavalink4NET/Players/LavalinkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1c7b3a0

Please sign in to comment.