Skip to content

Commit

Permalink
feature: Disconnect guild members from voice channels (#1311)
Browse files Browse the repository at this point in the history
* Feature: Disconnect users from voice channels

Updates GuildUserProperties to allow for setting either Channel or ChannelId to null, which will disconnect users from voice channels.

The type of ChannelId has been updated from a ulong to ulong?, which matches the latest api documentation.

* docs: update xmldoc wording

* breaking workaround, revert ChannelId to ulong

This is a workaround to prevent this PR from being a breaking
change. Reverts the type of GuildUserProperties#ChannelId to a
ulong from a ulong?. Guild Users may no longer be kicked by
setting this property to null, but setting
GuildUserProperties#Channel should still work.
  • Loading branch information
Chris-Johnston authored and foxbot committed Jun 5, 2019
1 parent 4433ca7 commit fc48c66
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/Discord.Net.Core/Entities/Users/GuildUserProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,19 @@ public class GuildUserProperties
/// </remarks>
public Optional<IEnumerable<ulong>> RoleIds { get; set; }
/// <summary>
/// Moves a user to a voice channel.
/// Moves a user to a voice channel. If <c>null</c>, this user will be disconnected from their current voice channel.
/// </summary>
/// <remarks>
/// This user MUST already be in a <see cref="IVoiceChannel"/> for this to work.
/// When set, this property takes precedence over <see cref="ChannelId"/>.
/// </remarks>
public Optional<IVoiceChannel> Channel { get; set; }
/// <summary>
/// Moves a user to a voice channel.
/// Moves a user to a voice channel. Set <see cref="Channel"/> to <c>null</c> to disconnect this user from their current voice channel.
/// </summary>
/// <remarks>
/// This user MUST already be in a <see cref="IVoiceChannel"/> for this to work.
/// </remarks>
public Optional<ulong> ChannelId { get; set; }
public Optional<ulong> ChannelId { get; set; } // TODO: v3 breaking change, change ChannelId to ulong? to allow for kicking users from voice
}
}
4 changes: 2 additions & 2 deletions src/Discord.Net.Rest/API/Rest/ModifyGuildMemberParams.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable CS1591
using Newtonsoft.Json;

namespace Discord.API.Rest
Expand All @@ -15,6 +15,6 @@ internal class ModifyGuildMemberParams
[JsonProperty("roles")]
public Optional<ulong[]> RoleIds { get; set; }
[JsonProperty("channel_id")]
public Optional<ulong> ChannelId { get; set; }
public Optional<ulong?> ChannelId { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Discord.Net.Rest/Entities/Users/UserHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Discord.API.Rest;
using Discord.API.Rest;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand Down Expand Up @@ -39,7 +39,7 @@ internal static class UserHelper
};

if (args.Channel.IsSpecified)
apiArgs.ChannelId = args.Channel.Value.Id;
apiArgs.ChannelId = args.Channel.Value?.Id;
else if (args.ChannelId.IsSpecified)
apiArgs.ChannelId = args.ChannelId.Value;

Expand Down

0 comments on commit fc48c66

Please sign in to comment.