diff --git a/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs index dac86d2d96..a0d6846a87 100644 --- a/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs @@ -59,5 +59,9 @@ public class TextChannelProperties : GuildChannelProperties /// Thrown if the value does not fall within [0, 21600]. public Optional DefaultSlowModeInterval { get; set; } + /// + /// Gets or sets the type of the channel. Only applicable for or channels. + /// + public Optional ChannelType { get; set; } } } diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index 65f0148049..143efd61ff 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -800,6 +800,21 @@ public interface IGuild : IDeletable, ISnowflakeEntity /// text channel. /// Task CreateTextChannelAsync(string name, Action func = null, RequestOptions options = null); + /// + /// Creates a new announcement channel in this guild. + /// + /// + /// Announcement channels are only available in Community guilds. + /// + /// The new name for the announcement channel. + /// The delegate containing the properties to be applied to the channel upon its creation. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the newly created + /// announcement channel. + /// + Task CreateNewsChannelAsync(string name, Action func = null, RequestOptions options = null); + /// /// Creates a new voice channel in this guild. /// diff --git a/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs index 6952b1a947..7884d74813 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs @@ -16,5 +16,8 @@ internal class ModifyTextChannelParams : ModifyGuildChannelParams [JsonProperty("default_thread_rate_limit_per_user")] public Optional DefaultSlowModeInterval { get; set; } + + [JsonProperty("type")] + public Optional Type { get; set; } } } diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index 3063ccfde3..f09616d356 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -49,6 +49,7 @@ public static Task ModifyAsync(ITextChannel channel, BaseDiscordClient cl func(args); var apiArgs = new API.Rest.ModifyTextChannelParams { + Type = args.ChannelType, Name = args.Name, Position = args.Position, CategoryId = args.CategoryId, diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 7558ee4cca..4627e50f7e 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -280,6 +280,39 @@ public static async Task CreateTextChannelAsync(IGuild guild, B var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return RestTextChannel.Create(client, guild, model); } + + /// is . + public static async Task CreateNewsChannelAsync(IGuild guild, BaseDiscordClient client, + string name, RequestOptions options, Action func = null) + { + if (name == null) + throw new ArgumentNullException(paramName: nameof(name)); + + var props = new TextChannelProperties(); + func?.Invoke(props); + + var args = new CreateGuildChannelParams(name, ChannelType.News) + { + CategoryId = props.CategoryId, + Topic = props.Topic, + IsNsfw = props.IsNsfw, + Position = props.Position, + SlowModeInterval = props.SlowModeInterval, + 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(), + DefaultAutoArchiveDuration = props.AutoArchiveDuration + }; + var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); + return RestNewsChannel.Create(client, guild, model); + } + /// is . public static async Task CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client, string name, RequestOptions options, Action func = null) diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index 0cbb9a05fe..7cb9d0dc6a 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -760,6 +760,11 @@ public async Task GetPublicUpdatesChannelAsync(RequestOptions o /// public Task CreateTextChannelAsync(string name, Action func = null, RequestOptions options = null) => GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func); + + /// + public Task CreateNewsChannelAsync(string name, Action func = null, RequestOptions options = null) + => GuildHelper.CreateNewsChannelAsync(this, Discord, name, options, func); + /// /// Creates a voice channel with the provided name. /// @@ -1547,6 +1552,9 @@ async Task IGuild.GetPublicUpdatesChannelAsync(CacheMode mode, Req async Task IGuild.CreateTextChannelAsync(string name, Action func, RequestOptions options) => await CreateTextChannelAsync(name, func, options).ConfigureAwait(false); /// + async Task IGuild.CreateNewsChannelAsync(string name, Action func, RequestOptions options) + => await CreateNewsChannelAsync(name, func, options).ConfigureAwait(false); + /// async Task IGuild.CreateVoiceChannelAsync(string name, Action func, RequestOptions options) => await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false); /// diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index 84c39d4751..e59673ead1 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -840,6 +840,11 @@ public SocketMediaChannel GetMediaChannel(ulong id) /// public Task CreateTextChannelAsync(string name, Action func = null, RequestOptions options = null) => GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func); + + /// + public Task CreateNewsChannelAsync(string name, Action func = null, RequestOptions options = null) + => GuildHelper.CreateNewsChannelAsync(this, Discord, name, options, func); + /// /// Creates a new voice channel in this guild. /// @@ -2132,6 +2137,11 @@ Task> IGuild.GetMediaChannelsAsync(CacheMode /// async Task IGuild.CreateTextChannelAsync(string name, Action func, RequestOptions options) => await CreateTextChannelAsync(name, func, options).ConfigureAwait(false); + + /// + async Task IGuild.CreateNewsChannelAsync(string name, Action func, RequestOptions options) + => await CreateNewsChannelAsync(name, func, options).ConfigureAwait(false); + /// async Task IGuild.CreateVoiceChannelAsync(string name, Action func, RequestOptions options) => await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false);