From b424bb2019147426dd8b5040dc6ad25fed96994a Mon Sep 17 00:00:00 2001 From: Quin Lynch <49576606+quinchs@users.noreply.github.com> Date: Wed, 9 Feb 2022 00:12:07 -0400 Subject: [PATCH] Fix Current user null on reconnect (#2092) --- src/Discord.Net.WebSocket/DiscordSocketClient.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 349e2714fb..e8e210e1af 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -46,6 +46,7 @@ public partial class DiscordSocketClient : BaseSocketClient, IDiscordClient private bool _isDisposed; private GatewayIntents _gatewayIntents; private ImmutableArray> _defaultStickers; + private SocketSelfUser _previousSessionUser; /// /// Provides access to a REST-only client with a shared state from this client. @@ -888,6 +889,7 @@ private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string ty _sessionId = data.SessionId; _unavailableGuildCount = unavailableGuilds; CurrentUser = currentUser; + _previousSessionUser = CurrentUser; State = state; } catch (Exception ex) @@ -930,6 +932,9 @@ private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string ty await GuildAvailableAsync(guild).ConfigureAwait(false); } + // Restore the previous sessions current user + CurrentUser = _previousSessionUser; + await _gatewayLogger.InfoAsync("Resumed previous session").ConfigureAwait(false); } break;