Browse Source

feature: Disconnect guild members from voice channels (#1311)

* 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.
tags/2.1.1
Chris Johnston Christopher F 6 years ago
parent
commit
fc48c6606d
3 changed files with 8 additions and 7 deletions
  1. +4
    -3
      src/Discord.Net.Core/Entities/Users/GuildUserProperties.cs
  2. +2
    -2
      src/Discord.Net.Rest/API/Rest/ModifyGuildMemberParams.cs
  3. +2
    -2
      src/Discord.Net.Rest/Entities/Users/UserHelper.cs

+ 4
- 3
src/Discord.Net.Core/Entities/Users/GuildUserProperties.cs View File

@@ -59,18 +59,19 @@ namespace Discord
/// </remarks> /// </remarks>
public Optional<IEnumerable<ulong>> RoleIds { get; set; } public Optional<IEnumerable<ulong>> RoleIds { get; set; }
/// <summary> /// <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> /// </summary>
/// <remarks> /// <remarks>
/// This user MUST already be in a <see cref="IVoiceChannel"/> for this to work. /// 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> /// </remarks>
public Optional<IVoiceChannel> Channel { get; set; } public Optional<IVoiceChannel> Channel { get; set; }
/// <summary> /// <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> /// </summary>
/// <remarks> /// <remarks>
/// This user MUST already be in a <see cref="IVoiceChannel"/> for this to work. /// This user MUST already be in a <see cref="IVoiceChannel"/> for this to work.
/// </remarks> /// </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
} }
} }

+ 2
- 2
src/Discord.Net.Rest/API/Rest/ModifyGuildMemberParams.cs View File

@@ -1,4 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable CS1591
using Newtonsoft.Json; using Newtonsoft.Json;


namespace Discord.API.Rest namespace Discord.API.Rest
@@ -15,6 +15,6 @@ namespace Discord.API.Rest
[JsonProperty("roles")] [JsonProperty("roles")]
public Optional<ulong[]> RoleIds { get; set; } public Optional<ulong[]> RoleIds { get; set; }
[JsonProperty("channel_id")] [JsonProperty("channel_id")]
public Optional<ulong> ChannelId { get; set; }
public Optional<ulong?> ChannelId { get; set; }
} }
} }

+ 2
- 2
src/Discord.Net.Rest/Entities/Users/UserHelper.cs View File

@@ -1,4 +1,4 @@
using Discord.API.Rest;
using Discord.API.Rest;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -39,7 +39,7 @@ namespace Discord.Rest
}; };


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




Loading…
Cancel
Save