From 97078b557a475b13ec440edd6c9d763333f63c42 Mon Sep 17 00:00:00 2001 From: RogueException Date: Tue, 21 Jun 2016 12:19:40 -0300 Subject: [PATCH] Ensure socket is disconnected before reconnecting --- src/Discord.Net/DiscordSocketClient.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Discord.Net/DiscordSocketClient.cs b/src/Discord.Net/DiscordSocketClient.cs index d21687212..a2117a846 100644 --- a/src/Discord.Net/DiscordSocketClient.cs +++ b/src/Discord.Net/DiscordSocketClient.cs @@ -163,6 +163,10 @@ namespace Discord if (LoginState != LoginState.LoggedIn) throw new InvalidOperationException("You must log in before connecting."); + var state = ConnectionState; + if (state == ConnectionState.Connecting || state == ConnectionState.Connected) + await DisconnectInternalAsync().ConfigureAwait(false); + ConnectionState = ConnectionState.Connecting; await _gatewayLogger.InfoAsync("Connecting"); try