diff --git a/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs index e580a2e596..2ac6c8d526 100644 --- a/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs @@ -29,6 +29,6 @@ public class GuildChannelProperties /// /// Sets the category for this channel /// - public Optional ParentId { get; set; } + public Optional CategoryId { get; set; } } } diff --git a/src/Discord.Net.Core/Entities/Channels/GuildChannelCategoryProperties.cs b/src/Discord.Net.Core/Entities/Channels/IChannelCategory.cs similarity index 60% rename from src/Discord.Net.Core/Entities/Channels/GuildChannelCategoryProperties.cs rename to src/Discord.Net.Core/Entities/Channels/IChannelCategory.cs index 2678e5eeff..bd20d76396 100644 --- a/src/Discord.Net.Core/Entities/Channels/GuildChannelCategoryProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/IChannelCategory.cs @@ -6,7 +6,7 @@ namespace Discord { - //public class GuildChannelCategoryProperties : GuildChannelProperties - //{ - //} + public interface IChannelCategory : IGuildChannel + { + } } diff --git a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs index b019fab23a..d2683018ff 100644 --- a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs @@ -10,9 +10,9 @@ public interface IGuildChannel : IChannel, IDeletable int Position { get; } /// Gets the parentid (category) of this channel in the guild's channel list. - ulong? ParentId { get; } + ulong? CategoryId { get; } /// Gets the parent channel (category) of this channel. - Task GetParentChannelAsync(); + Task GetCategory(); /// Gets the guild this channel is a member of. IGuild Guild { get; } /// Gets the id of the guild this channel is a member of. diff --git a/src/Discord.Net.Core/Entities/Channels/IGuildChannelCategory.cs b/src/Discord.Net.Core/Entities/Channels/IGuildChannelCategory.cs deleted file mode 100644 index fa603e87b6..0000000000 --- a/src/Discord.Net.Core/Entities/Channels/IGuildChannelCategory.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Discord -{ - public interface IGuildChannelCategory : IGuildChannel - { - ///// Modifies this text channel. - //Task ModifyAsync(Action func, RequestOptions options = null); - } -} diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index ee65fa3d4a..aa61fbd805 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -84,7 +84,7 @@ public interface IGuild : IDeletable, ISnowflakeEntity Task> GetTextChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetTextChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task> GetVoiceChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); - Task> GetChannelCategoriesAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + Task> GetChannelCategoriesAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetVoiceChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetAFKChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetSystemChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); @@ -94,6 +94,8 @@ public interface IGuild : IDeletable, ISnowflakeEntity Task CreateTextChannelAsync(string name, RequestOptions options = null); /// Creates a new voice channel. Task CreateVoiceChannelAsync(string name, RequestOptions options = null); + /// Creates a new channel category. + Task CreateChannelCategoryAsync(string name, RequestOptions options = null); Task> GetIntegrationsAsync(RequestOptions options = null); Task CreateIntegrationAsync(ulong id, string type, RequestOptions options = null); diff --git a/src/Discord.Net.Rest/API/Common/Channel.cs b/src/Discord.Net.Rest/API/Common/Channel.cs index f986ab59bb..97c35a57bd 100644 --- a/src/Discord.Net.Rest/API/Common/Channel.cs +++ b/src/Discord.Net.Rest/API/Common/Channel.cs @@ -24,7 +24,7 @@ internal class Channel [JsonProperty("permission_overwrites")] public Optional PermissionOverwrites { get; set; } [JsonProperty("parent_id")] - public ulong? ParentId { get; set; } + public ulong? CategoryId { get; set; } //TextChannel [JsonProperty("topic")] diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelCategoryParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelCategoryParams.cs deleted file mode 100644 index 293ade18e3..0000000000 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelCategoryParams.cs +++ /dev/null @@ -1,14 +0,0 @@ -#pragma warning disable CS1591 -using Newtonsoft.Json; - -namespace Discord.API.Rest -{ - [JsonObject(MemberSerialization = MemberSerialization.OptIn)] - internal class ModifyGuildChannelCategoryParams - { - [JsonProperty("name")] - public Optional Name { get; set; } - [JsonProperty("position")] - public Optional Position { get; set; } - } -} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs index 5bf615d603..120eeb3a8b 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs @@ -11,6 +11,6 @@ internal class ModifyGuildChannelParams [JsonProperty("position")] public Optional Position { get; set; } [JsonProperty("parent_id")] - public Optional ParentId { get; set; } + public Optional CategoryId { get; set; } } } diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index ebfd38e24f..4c265f3aad 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -28,7 +28,7 @@ internal static class ChannelHelper { Name = args.Name, Position = args.Position, - ParentId = args.ParentId + CategoryId = args.CategoryId }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); } @@ -42,7 +42,7 @@ internal static class ChannelHelper { Name = args.Name, Position = args.Position, - ParentId = args.ParentId, + CategoryId = args.CategoryId, Topic = args.Topic, IsNsfw = args.IsNsfw }; @@ -59,7 +59,7 @@ internal static class ChannelHelper Bitrate = args.Bitrate, Name = args.Name, Position = args.Position, - ParentId = args.ParentId, + CategoryId = args.CategoryId, UserLimit = args.UserLimit.IsSpecified ? (args.UserLimit.Value ?? 0) : Optional.Create() }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); diff --git a/src/Discord.Net.Rest/Entities/Channels/RestChannelCategory.cs b/src/Discord.Net.Rest/Entities/Channels/RestChannelCategory.cs new file mode 100644 index 0000000000..acea5a981f --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Channels/RestChannelCategory.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Model = Discord.API.Channel; + +namespace Discord.Rest +{ + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class RestChannelCategory : RestGuildChannel, IChannelCategory + { + public string Mention => MentionUtils.MentionChannel(Id); + + internal RestChannelCategory(BaseDiscordClient discord, IGuild guild, ulong id) + : base(discord, guild, id) + { + } + internal new static RestChannelCategory Create(BaseDiscordClient discord, IGuild guild, Model model) + { + var entity = new RestChannelCategory(discord, guild, model.Id); + entity.Update(model); + return entity; + } + + private string DebuggerDisplay => $"{Name} ({Id}, Category)"; + + // IGuildChannel + IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + Task IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) + => throw new NotSupportedException(); + Task> IGuildChannel.GetInvitesAsync(RequestOptions options) + => throw new NotSupportedException(); + + //IChannel + IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + } +} diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs index 4524adf27c..f007552198 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs @@ -16,8 +16,8 @@ public class RestGuildChannel : RestChannel, IGuildChannel, IUpdateable internal IGuild Guild { get; } public string Name { get; private set; } public int Position { get; private set; } - public ulong? ParentId { get; private set; } - public Task GetParentChannelAsync() => ParentId == null ? null : Guild.GetChannelAsync(ParentId.Value); + public ulong? CategoryId { get; private set; } + public async Task GetCategory() => CategoryId == null ? null : await Guild.GetChannelAsync(CategoryId.Value) as IChannelCategory; public ulong GuildId => Guild.Id; @@ -34,6 +34,8 @@ internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, return RestTextChannel.Create(discord, guild, model); case ChannelType.Voice: return RestVoiceChannel.Create(discord, guild, model); + case ChannelType.Category: + return RestChannelCategory.Create(discord, guild, model); default: // TODO: Channel categories return new RestGuildChannel(discord, guild, model.Id); diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannelCategory.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannelCategory.cs deleted file mode 100644 index e4a59b30a5..0000000000 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannelCategory.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Model = Discord.API.Channel; - -namespace Discord.Rest -{ - [DebuggerDisplay(@"{DebuggerDisplay,nq}")] - public class RestGuildChannelCategory : RestGuildChannel, IGuildChannelCategory - { - public string Mention => MentionUtils.MentionChannel(Id); - - internal RestGuildChannelCategory(BaseDiscordClient discord, IGuild guild, ulong id) - : base(discord, guild, id) - { - } - internal new static RestGuildChannelCategory Create(BaseDiscordClient discord, IGuild guild, Model model) - { - var entity = new RestGuildChannelCategory(discord, guild, model.Id); - entity.Update(model); - return entity; - } - internal override void Update(Model model) - { - base.Update(model); - } - - public Task GetUserAsync(ulong id, RequestOptions options = null) - => ChannelHelper.GetUserAsync(this, Guild, Discord, id, options); - public IAsyncEnumerable> GetUsersAsync(RequestOptions options = null) - => ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options); - - private string DebuggerDisplay => $"{Name} ({Id}, Text)"; - } -} diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 2fa29928c5..64c5899e49 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -157,6 +157,15 @@ internal static class GuildHelper var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return RestVoiceChannel.Create(client, guild, model); } + public static async Task CreateChannelCategoryAsync(IGuild guild, BaseDiscordClient client, + string name, RequestOptions options) + { + if (name == null) throw new ArgumentNullException(nameof(name)); + + var args = new CreateGuildChannelParams(name, ChannelType.Category); + var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); + return RestChannelCategory.Create(client, guild, model); + } //Integrations public static async Task> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client, diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index 66e6ba7397..101d9ca21b 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -176,10 +176,10 @@ public async Task> GetVoiceChannelsAsync(R var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); return channels.Select(x => x as RestVoiceChannel).Where(x => x != null).ToImmutableArray(); } - public async Task> GetChannelCategoriesAsync(RequestOptions options = null) + public async Task> GetChannelCategoriesAsync(RequestOptions options = null) { var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); - return channels.Select(x => x as RestGuildChannelCategory).Where(x => x != null).ToImmutableArray(); + return channels.Select(x => x as RestChannelCategory).Where(x => x != null).ToImmutableArray(); } public async Task GetAFKChannelAsync(RequestOptions options = null) @@ -222,6 +222,8 @@ public Task CreateTextChannelAsync(string name, RequestOptions => GuildHelper.CreateTextChannelAsync(this, Discord, name, options); public Task CreateVoiceChannelAsync(string name, RequestOptions options = null) => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); + public Task CreateChannelCategoryAsync(string name, RequestOptions options = null) + => GuildHelper.CreateChannelCategoryAsync(this, Discord, name, options); //Integrations public Task> GetIntegrationsAsync(RequestOptions options = null) @@ -309,7 +311,7 @@ async Task> IGuild.GetVoiceChannelsAsync(Cach else return ImmutableArray.Create(); } - async Task> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) + async Task> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) { if (mode == CacheMode.AllowDownload) return await GetChannelCategoriesAsync(options).ConfigureAwait(false); @@ -355,6 +357,8 @@ async Task IGuild.CreateTextChannelAsync(string name, RequestOptio => await CreateTextChannelAsync(name, options).ConfigureAwait(false); async Task IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) => await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); + async Task IGuild.CreateChannelCategoryAsync(string name, RequestOptions options) + => await CreateChannelCategoryAsync(name, options).ConfigureAwait(false); async Task> IGuild.GetIntegrationsAsync(RequestOptions options) => await GetIntegrationsAsync(options).ConfigureAwait(false); diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs index 02f04df939..92f5e90137 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs @@ -10,7 +10,7 @@ public class RpcGuildChannel : RpcChannel, IGuildChannel { public ulong GuildId { get; } public int Position { get; private set; } - public ulong? ParentId { get; private set; } + public ulong? CategoryId { get; private set; } internal RpcGuildChannel(DiscordRpcClient discord, ulong id, ulong guildId) : base(discord, id) @@ -58,7 +58,7 @@ public async Task CreateInviteAsync(int? maxAge = 3600, int? public override string ToString() => Name; //IGuildChannel - public Task GetParentChannelAsync() + public Task GetCategory() { //Always fails throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object."); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelCategory.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelCategory.cs new file mode 100644 index 0000000000..e1f7645518 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelCategory.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Discord.Audio; +using Discord.Rest; +using Model = Discord.API.Channel; + +namespace Discord.WebSocket +{ + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class SocketChannelCategory : SocketGuildChannel, IChannelCategory + { + public override IReadOnlyCollection Users + => Guild.Users.Where(x => x.VoiceChannel?.Id == Id).ToImmutableArray(); + + internal SocketChannelCategory(DiscordSocketClient discord, ulong id, SocketGuild guild) + : base(discord, id, guild) + { + } + internal new static SocketChannelCategory Create(SocketGuild guild, ClientState state, Model model) + { + var entity = new SocketChannelCategory(guild.Discord, model.Id, guild); + entity.Update(state, model); + return entity; + } + + private string DebuggerDisplay => $"{Name} ({Id}, Category)"; + internal new SocketChannelCategory Clone() => MemberwiseClone() as SocketChannelCategory; + + // IGuildChannel + IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + Task IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) + => throw new NotSupportedException(); + Task> IGuildChannel.GetInvitesAsync(RequestOptions options) + => throw new NotSupportedException(); + + //IChannel + IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs index 64233f7421..7255a7fa3b 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs @@ -17,9 +17,9 @@ public class SocketGuildChannel : SocketChannel, IGuildChannel public SocketGuild Guild { get; } public string Name { get; private set; } public int Position { get; private set; } - public ulong? ParentId { get; private set; } - public IGuildChannel ParentChannel => ParentId == null ? null : Guild.GetChannel(ParentId.Value); - public Task GetParentChannelAsync() => Task.FromResult(ParentChannel); + public ulong? CategoryId { get; private set; } + public IChannelCategory Category => CategoryId == null ? null : Guild.GetChannel(CategoryId.Value) as IChannelCategory; + Task IGuildChannel.GetCategory() => Task.FromResult(Category); public IReadOnlyCollection PermissionOverwrites => _overwrites; public new virtual IReadOnlyCollection Users => ImmutableArray.Create(); @@ -38,7 +38,7 @@ internal static SocketGuildChannel Create(SocketGuild guild, ClientState state, case ChannelType.Voice: return SocketVoiceChannel.Create(guild, state, model); case ChannelType.Category: - return SocketGuildChannelCategory.Create(guild, state, model); + return SocketChannelCategory.Create(guild, state, model); default: // TODO: Proper implementation for channel categories return new SocketGuildChannel(guild.Discord, model.Id, guild); @@ -48,7 +48,7 @@ internal override void Update(ClientState state, Model model) { Name = model.Name.Value; Position = model.Position.Value; - ParentId = model.ParentId; + CategoryId = model.CategoryId; var overwrites = model.PermissionOverwrites.Value; var newOverwrites = ImmutableArray.CreateBuilder(overwrites.Length); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannelCategory.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannelCategory.cs deleted file mode 100644 index d23060f787..0000000000 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannelCategory.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Discord.Audio; -using Discord.Rest; -using Model = Discord.API.Channel; - -namespace Discord.WebSocket -{ - [DebuggerDisplay(@"{DebuggerDisplay,nq}")] - public class SocketGuildChannelCategory : SocketGuildChannel, IGuildChannelCategory - { - public override IReadOnlyCollection Users - => Guild.Users.Where(x => x.VoiceChannel?.Id == Id).ToImmutableArray(); - - internal SocketGuildChannelCategory(DiscordSocketClient discord, ulong id, SocketGuild guild) - : base(discord, id, guild) - { - } - internal new static SocketGuildChannelCategory Create(SocketGuild guild, ClientState state, Model model) - { - var entity = new SocketGuildChannelCategory(guild.Discord, model.Id, guild); - entity.Update(state, model); - return entity; - } - internal override void Update(ClientState state, Model model) - { - base.Update(state, model); - } - - public override SocketGuildUser GetUser(ulong id) - { - var user = Guild.GetUser(id); - if (user?.VoiceChannel?.Id == Id) - return user; - return null; - } - - private string DebuggerDisplay => $"{Name} ({Id}, Category)"; - internal new SocketGuildChannelCategory Clone() => MemberwiseClone() as SocketGuildChannelCategory; - } -} diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index b2529951ac..9d64db415e 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -94,8 +94,8 @@ public IReadOnlyCollection TextChannels => Channels.Select(x => x as SocketTextChannel).Where(x => x != null).ToImmutableArray(); public IReadOnlyCollection VoiceChannels => Channels.Select(x => x as SocketVoiceChannel).Where(x => x != null).ToImmutableArray(); - public IReadOnlyCollection ChannelCategories - => Channels.Select(x => x as SocketGuildChannelCategory).Where(x => x != null).ToImmutableArray(); + public IReadOnlyCollection ChannelCategories + => Channels.Select(x => x as SocketChannelCategory).Where(x => x != null).ToImmutableArray(); public SocketGuildUser CurrentUser => _members.TryGetValue(Discord.CurrentUser.Id, out SocketGuildUser member) ? member : null; public SocketRole EveryoneRole => GetRole(Id); public IReadOnlyCollection Channels @@ -318,6 +318,9 @@ public Task CreateTextChannelAsync(string name, RequestOptions => GuildHelper.CreateTextChannelAsync(this, Discord, name, options); public Task CreateVoiceChannelAsync(string name, RequestOptions options = null) => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); + public Task CreateChannelCategoryAsync(string name, RequestOptions options = null) + => GuildHelper.CreateChannelCategoryAsync(this, Discord, name, options); + internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model) { var channel = SocketGuildChannel.Create(this, state, model); @@ -636,8 +639,8 @@ Task IGuild.GetTextChannelAsync(ulong id, CacheMode mode, RequestO => Task.FromResult(GetTextChannel(id)); Task> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(VoiceChannels); - Task> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) - => Task.FromResult>(ChannelCategories); + Task> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) + => Task.FromResult>(ChannelCategories); Task IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetVoiceChannel(id)); Task IGuild.GetAFKChannelAsync(CacheMode mode, RequestOptions options) @@ -652,6 +655,8 @@ async Task IGuild.CreateTextChannelAsync(string name, RequestOptio => await CreateTextChannelAsync(name, options).ConfigureAwait(false); async Task IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) => await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); + async Task IGuild.CreateChannelCategoryAsync(string name, RequestOptions options) + => await CreateChannelCategoryAsync(name, options).ConfigureAwait(false); async Task> IGuild.GetIntegrationsAsync(RequestOptions options) => await GetIntegrationsAsync(options).ConfigureAwait(false);