Allow creating announcement channels (#2837)
This commit is contained in:
@@ -59,5 +59,9 @@ namespace Discord
|
|||||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if the value does not fall within [0, 21600].</exception>
|
/// <exception cref="ArgumentOutOfRangeException">Thrown if the value does not fall within [0, 21600].</exception>
|
||||||
public Optional<int> DefaultSlowModeInterval { get; set; }
|
public Optional<int> DefaultSlowModeInterval { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the type of the channel. Only applicable for <see cref="ChannelType.Text"/> or <see cref="ChannelType.News"/> channels.
|
||||||
|
/// </summary>
|
||||||
|
public Optional<ChannelType> ChannelType { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -800,6 +800,21 @@ namespace Discord
|
|||||||
/// text channel.
|
/// text channel.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
Task<ITextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null);
|
Task<ITextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null);
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new announcement channel in this guild.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Announcement channels are only available in Community guilds.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="name">The new name for the announcement channel.</param>
|
||||||
|
/// <param name="func">The delegate containing the properties to be applied to the channel upon its creation.</param>
|
||||||
|
/// <param name="options">The options to be used when sending the request.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// A task that represents the asynchronous creation operation. The task result contains the newly created
|
||||||
|
/// announcement channel.
|
||||||
|
/// </returns>
|
||||||
|
Task<INewsChannel> CreateNewsChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new voice channel in this guild.
|
/// Creates a new voice channel in this guild.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -16,5 +16,8 @@ namespace Discord.API.Rest
|
|||||||
|
|
||||||
[JsonProperty("default_thread_rate_limit_per_user")]
|
[JsonProperty("default_thread_rate_limit_per_user")]
|
||||||
public Optional<int> DefaultSlowModeInterval { get; set; }
|
public Optional<int> DefaultSlowModeInterval { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("type")]
|
||||||
|
public Optional<ChannelType> Type { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ namespace Discord.Rest
|
|||||||
func(args);
|
func(args);
|
||||||
var apiArgs = new API.Rest.ModifyTextChannelParams
|
var apiArgs = new API.Rest.ModifyTextChannelParams
|
||||||
{
|
{
|
||||||
|
Type = args.ChannelType,
|
||||||
Name = args.Name,
|
Name = args.Name,
|
||||||
Position = args.Position,
|
Position = args.Position,
|
||||||
CategoryId = args.CategoryId,
|
CategoryId = args.CategoryId,
|
||||||
|
|||||||
@@ -280,6 +280,39 @@ namespace Discord.Rest
|
|||||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
|
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||||
return RestTextChannel.Create(client, guild, model);
|
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>
|
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <see langword="null" />.</exception>
|
||||||
public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
|
public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
|
||||||
string name, RequestOptions options, Action<VoiceChannelProperties> func = null)
|
string name, RequestOptions options, Action<VoiceChannelProperties> func = null)
|
||||||
|
|||||||
@@ -760,6 +760,11 @@ namespace Discord.Rest
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public Task<RestTextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null)
|
public Task<RestTextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null)
|
||||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func);
|
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func);
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IGuild.CreateNewsChannelAsync"/>
|
||||||
|
public Task<RestNewsChannel> CreateNewsChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null)
|
||||||
|
=> GuildHelper.CreateNewsChannelAsync(this, Discord, name, options, func);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a voice channel with the provided name.
|
/// Creates a voice channel with the provided name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1547,6 +1552,9 @@ namespace Discord.Rest
|
|||||||
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, Action<TextChannelProperties> func, RequestOptions options)
|
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, Action<TextChannelProperties> func, RequestOptions options)
|
||||||
=> await CreateTextChannelAsync(name, func, options).ConfigureAwait(false);
|
=> await CreateTextChannelAsync(name, func, options).ConfigureAwait(false);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
async Task<INewsChannel> IGuild.CreateNewsChannelAsync(string name, Action<TextChannelProperties> func, RequestOptions options)
|
||||||
|
=> await CreateNewsChannelAsync(name, func, options).ConfigureAwait(false);
|
||||||
|
/// <inheritdoc />
|
||||||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func, RequestOptions options)
|
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func, RequestOptions options)
|
||||||
=> await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false);
|
=> await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -840,6 +840,11 @@ namespace Discord.WebSocket
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public Task<RestTextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null)
|
public Task<RestTextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null)
|
||||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func);
|
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func);
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IGuild.CreateNewsChannelAsync"/>
|
||||||
|
public Task<RestNewsChannel> CreateNewsChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null)
|
||||||
|
=> GuildHelper.CreateNewsChannelAsync(this, Discord, name, options, func);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new voice channel in this guild.
|
/// Creates a new voice channel in this guild.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -2132,6 +2137,11 @@ namespace Discord.WebSocket
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, Action<TextChannelProperties> func, RequestOptions options)
|
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, Action<TextChannelProperties> func, RequestOptions options)
|
||||||
=> await CreateTextChannelAsync(name, func, options).ConfigureAwait(false);
|
=> await CreateTextChannelAsync(name, func, options).ConfigureAwait(false);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
async Task<INewsChannel> IGuild.CreateNewsChannelAsync(string name, Action<TextChannelProperties> func, RequestOptions options)
|
||||||
|
=> await CreateNewsChannelAsync(name, func, options).ConfigureAwait(false);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func, RequestOptions options)
|
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func, RequestOptions options)
|
||||||
=> await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false);
|
=> await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user