diff --git a/src/Discord.Net.WebSocket/Audio/AudioClient.cs b/src/Discord.Net.WebSocket/Audio/AudioClient.cs index fe8d763b3..d5e9895a0 100644 --- a/src/Discord.Net.WebSocket/Audio/AudioClient.cs +++ b/src/Discord.Net.WebSocket/Audio/AudioClient.cs @@ -47,15 +47,17 @@ namespace Discord.Audio public SocketGuild Guild { get; } public DiscordVoiceAPIClient ApiClient { get; private set; } public int Latency { get; private set; } + public ulong ChannelId { get; internal set; } private DiscordSocketClient Discord => Guild.Discord; public ConnectionState ConnectionState => _connection.State; /// Creates a new REST/WebSocket discord client. - internal AudioClient(SocketGuild guild, int id) + internal AudioClient(SocketGuild guild, int clientId, ulong channelId) { Guild = guild; - _audioLogger = Discord.LogManager.CreateLogger($"Audio #{id}"); + ChannelId = channelId; + _audioLogger = Discord.LogManager.CreateLogger($"Audio #{clientId}"); ApiClient = new DiscordVoiceAPIClient(guild.Id, Discord.WebSocketProvider, Discord.UdpSocketProvider); ApiClient.SentGatewayMessage += async opCode => await _audioLogger.DebugAsync($"Sent {opCode}").ConfigureAwait(false); diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index a71e1e916..e261d118f 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -433,7 +433,13 @@ namespace Discord.WebSocket if (_audioClient != null && before.VoiceChannel?.Id != after.VoiceChannel?.Id) { if (model.UserId == CurrentUser.Id) - await RepopulateAudioStreamsAsync().ConfigureAwait(false); + { + if (after.VoiceChannel != null && _audioClient.ChannelId != after.VoiceChannel?.Id) + { + _audioClient.ChannelId = after.VoiceChannel.Id; + await RepopulateAudioStreamsAsync().ConfigureAwait(false); + } + } else { await _audioClient.RemoveInputStreamAsync(model.UserId).ConfigureAwait(false); //User changed channels, end their stream @@ -480,7 +486,7 @@ namespace Discord.WebSocket if (_audioClient == null) { - var audioClient = new AudioClient(this, Discord.GetAudioId()); + var audioClient = new AudioClient(this, Discord.GetAudioId(), channelId); audioClient.Disconnected += async ex => { if (!promise.Task.IsCompleted)