Allow creating announcement channels (#2837)

This commit is contained in:
Mihail Gribkov
2024-02-11 23:48:40 +03:00
committed by GitHub
parent 4d7e384e51
commit f1777de164
7 changed files with 74 additions and 0 deletions

View File

@@ -280,6 +280,39 @@ namespace Discord.Rest
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
return RestTextChannel.Create(client, guild, model);
}
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <see langword="null" />.</exception>
public static async Task<RestNewsChannel> CreateNewsChannelAsync(IGuild guild, BaseDiscordClient client,
string name, RequestOptions options, Action<TextChannelProperties> 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<API.Overwrite[]>(),
DefaultAutoArchiveDuration = props.AutoArchiveDuration
};
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
return RestNewsChannel.Create(client, guild, model);
}
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <see langword="null" />.</exception>
public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
string name, RequestOptions options, Action<VoiceChannelProperties> func = null)