diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index 796abb784..77373b9fc 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -22,6 +22,7 @@ namespace Discord private readonly JsonSerializer _serializer; private readonly ConcurrentQueue _pendingMessages; private readonly ConcurrentDictionary _voiceClients; + private bool _sentInitialLog; /// Returns the current logged-in user. public User CurrentUser => _currentUser; @@ -219,9 +220,12 @@ namespace Discord /// Returns a token for future connections. public new async Task Connect(string email, string password) { + if (!_sentInitialLog) + SendInitialLog(); + if (State != DiscordClientState.Disconnected) await Disconnect().ConfigureAwait(false); - + string token; try { @@ -240,6 +244,9 @@ namespace Discord /// Connects to the Discord server with the provided token. public async Task Connect(string token) { + if (!_sentInitialLog) + SendInitialLog(); + if (State != (int)DiscordClientState.Disconnected) await Disconnect().ConfigureAwait(false); @@ -729,7 +736,9 @@ namespace Discord return client; } - async Task LeaveVoiceServer(string serverId) + public Task LeaveVoiceServer(Server server) + => LeaveVoiceServer(server?.Id); + public async Task LeaveVoiceServer(string serverId) { CheckReady(); //checkVoice is done inside the voice client if (serverId == null) throw new ArgumentNullException(nameof(serverId)); @@ -738,5 +747,12 @@ namespace Discord if (_voiceClients.TryRemove(serverId, out client)) await client.Disconnect(); } + + private void SendInitialLog() + { + if (_config.LogLevel >= LogMessageSeverity.Verbose) + RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Client, $"Config: {JsonConvert.SerializeObject(_config)}"); + _sentInitialLog = true; + } } } diff --git a/src/Discord.Net/DiscordSimpleClient.Voice.cs b/src/Discord.Net/DiscordSimpleClient.Voice.cs index b132a7a05..a62b8b612 100644 --- a/src/Discord.Net/DiscordSimpleClient.Voice.cs +++ b/src/Discord.Net/DiscordSimpleClient.Voice.cs @@ -9,7 +9,6 @@ namespace Discord public interface IDiscordVoiceClient { Task JoinChannel(string channelId); - Task Disconnect(); void SendVoicePCM(byte[] data, int count); void ClearVoicePCM(); @@ -24,7 +23,7 @@ namespace Discord CheckReady(checkVoice: true); if (channelId == null) throw new ArgumentNullException(nameof(channelId)); - await ((IDiscordVoiceClient)this).Disconnect().ConfigureAwait(false); + await _voiceSocket.Disconnect().ConfigureAwait(false); _voiceSocket.SetChannel(_voiceServerId, channelId); _dataSocket.SendJoinVoice(_voiceServerId, channelId); @@ -38,12 +37,12 @@ namespace Discord catch (TimeoutException) { tokenSource.Cancel(); - await ((IDiscordVoiceClient)this).Disconnect().ConfigureAwait(false); + await _voiceSocket.Disconnect().ConfigureAwait(false); throw; } } - async Task IDiscordVoiceClient.Disconnect() + /*async Task IDiscordVoiceClient.Disconnect() { CheckReady(checkVoice: true); @@ -55,7 +54,7 @@ namespace Discord _dataSocket.SendLeaveVoice(_voiceSocket.CurrentServerId); } } - } + }*/ /// Sends a PCM frame to the voice server. Will block until space frees up in the outgoing buffer. /// PCM frame to send. This must be a single or collection of uncompressed 48Kz monochannel 20ms PCM frames.