/// <summary>
        /// Disconnects and disposes this voice connection.
        /// </summary>
        public void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }

            IsDisposed    = true;
            IsInitialized = false;
            TokenSource.Cancel();
#if !NETSTANDARD1_1
            if (Configuration.EnableIncoming)
            {
                ReceiverTokenSource.Cancel();
            }
#endif

            try
            {
                VoiceWs.DisconnectAsync(null).ConfigureAwait(false).GetAwaiter().GetResult();
                UdpClient.Close();
            }
            catch (Exception)
            { }

            Opus?.Dispose();
            Opus   = null;
            Sodium = null;
            Rtp    = null;

            if (VoiceDisconnected != null)
            {
                VoiceDisconnected(Guild);
            }
        }
示例#2
0
 internal Task ReconnectAsync()
 => VoiceWs.DisconnectAsync(new SocketCloseEventArgs(Discord));