From dd9b72a05d9164158f513634e6ffd9948c6d1386 Mon Sep 17 00:00:00 2001 From: RogueException Date: Sat, 17 Oct 2015 00:59:50 -0300 Subject: [PATCH] Fixed LeaveVoiceServer when Multiserver is disabled --- src/Discord.Net/DiscordClient.cs | 16 ++++++++++++---- src/Discord.Net/DiscordSimpleClient.cs | 9 +++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index 1d121ae8a..4789b30de 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -798,10 +798,18 @@ namespace Discord CheckReady(); //checkVoice is done inside the voice client if (serverId == null) throw new ArgumentNullException(nameof(serverId)); - DiscordSimpleClient client; - if (_voiceClients.TryRemove(serverId, out client)) - await client.Disconnect(); - } + if (Config.EnableVoiceMultiserver) + { + DiscordSimpleClient client; + if (_voiceClients.TryRemove(serverId, out client)) + await client.Disconnect(); + } + else + { + _dataSocket.SendLeaveVoice(serverId); + await _voiceSocket.Disconnect(); + } + } private void SendInitialLog() { diff --git a/src/Discord.Net/DiscordSimpleClient.cs b/src/Discord.Net/DiscordSimpleClient.cs index 6889519a8..f24495169 100644 --- a/src/Discord.Net/DiscordSimpleClient.cs +++ b/src/Discord.Net/DiscordSimpleClient.cs @@ -248,10 +248,15 @@ namespace Discord protected virtual async Task Cleanup() { - await _dataSocket.Disconnect().ConfigureAwait(false); if (_enableVoice) + { + string voiceServerId = _voiceSocket.CurrentServerId; + if (voiceServerId != null) + _dataSocket.SendLeaveVoice(voiceServerId); await _voiceSocket.Disconnect().ConfigureAwait(false); - + } + await _dataSocket.Disconnect().ConfigureAwait(false); + _currentUserId = null; _gateway = null; _token = null;