From f759f942f8cd413fe4996fd957d82c01b7b854bf Mon Sep 17 00:00:00 2001 From: Christopher F Date: Mon, 24 Apr 2017 20:34:18 -0400 Subject: [PATCH] Throw a preemptive exception when sending presence data before connect This prevents a later, less detailed nullref, when attempting to set the CurrentUser's presence data. This also removes a redundant CurrentUser assignment in the SetGameAsync method, since this will be set later on in the SendStatusAsync method. --- src/Discord.Net.WebSocket/DiscordSocketClient.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 4d79ff964..e0bf08e71 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -355,11 +355,12 @@ namespace Discord.WebSocket Game = new Game(name, streamUrl, streamType); else Game = null; - CurrentUser.Presence = new SocketPresence(Status, Game); await SendStatusAsync().ConfigureAwait(false); } private async Task SendStatusAsync() { + if (ConnectionState != ConnectionState.Connected) + throw new InvalidOperationException("Presence data cannot be sent while the client is disconnected."); var game = Game; var status = Status; var statusSince = _statusSince;