/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> public static async Task <RestCategoryChannel> CreateCategoryChannelAsync(IGuild guild, BaseDiscordClient client, string name, RequestOptions options, Action <GuildChannelProperties> func = null) { if (name == null) { throw new ArgumentNullException(paramName: nameof(name)); } var props = new GuildChannelProperties(); func?.Invoke(props); var args = new CreateGuildChannelParams(name, ChannelType.Category) { Position = props.Position, Overwrites = props.PermissionOverwrites.IsSpecified ? props.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite { TargetId = overwrite.TargetId, TargetType = overwrite.TargetType, Allow = overwrite.Permissions.AllowValue.ToString(), Deny = overwrite.Permissions.DenyValue.ToString() }).ToArray() : Optional.Create <API.Overwrite[]>(), }; var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return(RestCategoryChannel.Create(client, guild, model)); }
// Categories public static async Task<ICategoryChannel> GetCategoryAsync(INestedChannel channel, BaseDiscordClient client, RequestOptions options) { // if no category id specified, return null if (!channel.CategoryId.HasValue) return null; // CategoryId will contain a value here var model = await client.ApiClient.GetChannelAsync(channel.CategoryId.Value, options).ConfigureAwait(false); return RestCategoryChannel.Create(client, model) as ICategoryChannel; }
internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model) { return(model.Type switch { ChannelType.News => RestNewsChannel.Create(discord, guild, model), ChannelType.Text => RestTextChannel.Create(discord, guild, model), ChannelType.Voice => RestVoiceChannel.Create(discord, guild, model), ChannelType.Stage => RestStageChannel.Create(discord, guild, model), ChannelType.Category => RestCategoryChannel.Create(discord, guild, model), ChannelType.PublicThread or ChannelType.PrivateThread or ChannelType.NewsThread => RestThreadChannel.Create(discord, guild, model), _ => new RestGuildChannel(discord, guild, model.Id), });
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> public static async Task <RestCategoryChannel> CreateCategoryChannelAsync(IGuild guild, BaseDiscordClient client, string name, RequestOptions options) { if (name == null) { throw new ArgumentNullException(paramName: nameof(name)); } var args = new CreateGuildChannelParams(name, ChannelType.Category); var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return(RestCategoryChannel.Create(client, guild, model)); }
/// <exception cref="InvalidOperationException">Unexpected channel type.</exception> internal static RestChannel Create(BaseDiscordClient discord, Model model) { return(model.Type switch { ChannelType.News or ChannelType.Text or ChannelType.Voice or ChannelType.Stage or ChannelType.NewsThread or ChannelType.PrivateThread or ChannelType.PublicThread => RestGuildChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model), ChannelType.DM or ChannelType.Group => CreatePrivate(discord, model) as RestChannel, ChannelType.Category => RestCategoryChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model), _ => new RestChannel(discord, model.Id), });
internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model) { switch (model.Type) { case ChannelType.Text: return(RestTextChannel.Create(discord, guild, model)); case ChannelType.Voice: return(RestVoiceChannel.Create(discord, guild, model)); case ChannelType.Category: return(RestCategoryChannel.Create(discord, guild, model)); default: return(new RestGuildChannel(discord, guild, model.Id)); } }
internal static RestChannel Create(BaseDiscordClient discord, Model model) { switch (model.Type) { case ChannelType.Text: case ChannelType.Voice: return(RestGuildChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model)); case ChannelType.DM: case ChannelType.Group: return(CreatePrivate(discord, model) as RestChannel); case ChannelType.Category: return(RestCategoryChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model)); default: return(new RestChannel(discord, model.Id)); } }