/// <summary> /// Disconnects the player asynchronously. /// </summary> /// <returns>a task that represents the asynchronous operation</returns> internal async Task DisconnectAsync(PlayerDisconnectCause disconnectCause) { if (State == PlayerState.NotConnected) { return; } // keep old channel in memory var channel = VoiceChannelId; // disconnect from channel await Client.SendVoiceUpdateAsync(GuildId, null); VoiceChannelId = null; State = PlayerState.NotConnected; // only trigger event if disconnected from a channel if (channel.HasValue) { // notify disconnect await LavalinkSocket.NotifyDisconnectAsync( new PlayerDisconnectedEventArgs(this, channel.Value, disconnectCause)); } }
/// <summary> /// Initializes a new instance of the <see cref="PlayerDisconnectedEventArgs"/> class. /// </summary> /// <param name="player">the affected player</param> /// <param name="voiceChannelId"> /// the snowflake identifier of the voice channel disconnected from /// </param> /// <param name="disconnectCause">the reason why the player disconnected</param> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="player"/> is <see langword="null"/>. /// </exception> public PlayerDisconnectedEventArgs(LavalinkPlayer player, ulong voiceChannelId, PlayerDisconnectCause disconnectCause) : base(player) { VoiceChannelId = voiceChannelId; DisconnectCause = disconnectCause; }