From 3559c277fe33ead44468f8b6bd243dc6fc27e2e9 Mon Sep 17 00:00:00 2001 From: CottageDwellingCat <80918250+CottageDwellingCat@users.noreply.github.com> Date: Mon, 4 Oct 2021 09:56:43 -0500 Subject: [PATCH] Add channel types in application command options. (#217) * add channel types in application command options * Indent Docs --- .../Discord.Net.Commands.xml | 6 +- src/Discord.Net.Core/Discord.Net.Core.xml | 76 ++++++++++++------- .../Interactions/ApplicationCommandOption.cs | 5 +- .../Interactions/IApplicationCommandOption.cs | 5 ++ .../Slash Commands/SlashCommandBuilder.cs | 35 ++++++++- .../API/Common/ApplicationCommandOption.cs | 9 +++ src/Discord.Net.Rest/Discord.Net.Rest.xml | 29 ++++--- .../RestApplicationCommandOption.cs | 9 +++ .../Discord.Net.WebSocket.xml | 37 +++++---- .../SocketApplicationCommandOption.cs | 9 +++ 10 files changed, 158 insertions(+), 62 deletions(-) diff --git a/src/Discord.Net.Commands/Discord.Net.Commands.xml b/src/Discord.Net.Commands/Discord.Net.Commands.xml index 4ef47930e..b24a8fdd0 100644 --- a/src/Discord.Net.Commands/Discord.Net.Commands.xml +++ b/src/Discord.Net.Commands/Discord.Net.Commands.xml @@ -19,7 +19,7 @@ [Command("stats")] [Alias("stat", "info")] - public async Task GetStatsAsync(IUser user) + public Task GetStatsAsync(IUser user) { // ...pull stats } @@ -1142,7 +1142,7 @@ Specifies if notifications are sent for mentioned users and roles in the . If null, all mentioned roles and users will be notified. - The request options for this async request. + The request options for this request. The message references to be included. Used to reply to specific messages. The message components to be included with this message. Used for interactions. A collection of stickers to send with the file. @@ -1468,7 +1468,7 @@ - The default behaviour set in . + The default behavior set in . diff --git a/src/Discord.Net.Core/Discord.Net.Core.xml b/src/Discord.Net.Core/Discord.Net.Core.xml index eb93d48c9..a28214712 100644 --- a/src/Discord.Net.Core/Discord.Net.Core.xml +++ b/src/Discord.Net.Core/Discord.Net.Core.xml @@ -3600,12 +3600,12 @@ - Gets the text channel channel where admins and moderators of Community guilds receive notices from Discord. + Gets the text channel where admins and moderators of Community guilds receive notices from Discord. The that determines whether the object should be fetched from cache. The options to be used when sending the request. - A task that represents the asynchronous get operation. The task result contains the text channel channel where + A task that represents the asynchronous get operation. The task result contains the text channel where admins and moderators of Community guilds receive notices from Discord; if none is set. @@ -3835,7 +3835,7 @@ Downloads all users for this guild if the current list is incomplete. - This method downloads all users found within this guild throught the Gateway and caches them. + This method downloads all users found within this guild through the Gateway and caches them. A task that represents the asynchronous download operation. @@ -4564,6 +4564,11 @@ Gets or sets if this option is a subcommand or subcommand group type, these nested options will be the parameters. + + + Gets or sets the allowed channel types for this option. + + Represents a choice for a . This class is used when making new commands. @@ -4741,7 +4746,7 @@ - Returns the maximun length a commands name allowed by Discord + Returns the maximum length a commands name allowed by Discord @@ -4790,7 +4795,7 @@ - Returns the maximun length a commands name allowed by Discord + Returns the maximum length a commands name allowed by Discord @@ -4951,7 +4956,7 @@ - The discription of this command option, 1-100 character description. + The description of this command option, 1-100 character description. @@ -4974,6 +4979,11 @@ If the option is a subcommand or subcommand group type, this nested options will be the parameters. + + + The allowed channel types for this option. + + Specifies choices for command group. @@ -5056,7 +5066,7 @@ Gets the original response for this interaction. - The request options for this async request. + The request options for this request. A that represents the initial response. @@ -5064,7 +5074,7 @@ Edits original response for this interaction. A delegate containing the properties to modify the message with. - The request options for this async request. + The request options for this request. A that represents the initial response. @@ -5077,7 +5087,7 @@ - Represents an interface used to specify classes that they are a vaild dataype of a class. + Represents an interface used to specify classes that they are a vaild data type of a class. @@ -5971,7 +5981,7 @@ - Returns the maximun length a commands name allowed by Discord + Returns the maximum length a commands name allowed by Discord @@ -6034,7 +6044,7 @@ The default permission value to set. The current builder. - + Adds an option to the current slash command. @@ -6045,6 +6055,7 @@ If this option is the default option. If this option is set to autocompleate. The options of the option to add. + The allowed channel types for this option. The choices of this option. The current builder. @@ -6054,7 +6065,7 @@ The name of the option to add. The type of this option. - The sescription of this option. + The description of this option. The current builder. @@ -6126,13 +6137,18 @@ Gets or sets if this option is a subcommand or subcommand group type, these nested options will be the parameters. + + + Gets or sets the allowed channel types for this option. + + Builds the current option. The built version of this option. - + Adds an option to the current slash command. @@ -6143,6 +6159,7 @@ If this option is the default option. If this option supports autocomplete. The options of the option to add. + The allowed channel types for this option. The choices of this option. The current builder. @@ -6169,6 +6186,13 @@ The value of the choice. The current builder. + + + Adds a channnel type to the current option. + + The to add. + The current builder. + Sets the current builders name. @@ -6218,7 +6242,7 @@ - The discription of this command. + The description of this command. @@ -7604,7 +7628,7 @@ Gets the clean content for this message. - A string that contains the body of the message stripped of mentions, markdown, emojiis and pings; note that this field may be empty if there is an embed. + A string that contains the body of the message stripped of mentions, markdown, emojis and pings; note that this field may be empty if there is an embed. @@ -8407,7 +8431,7 @@ If the is null then the default 0 will be used. - A string thats compatable in a discord message, ex: <t:1625944201:f> + A string thats compatible in a discord message, ex: <t:1625944201:f> @@ -8778,7 +8802,7 @@ If true, a user may stream video in a voice channel. - If true, a user may adjust role permissions. This also implictly grants all other permissions. + If true, a user may adjust role permissions. This also implicitly grants all other permissions. If true, a user may edit the webhooks for this channel. @@ -8805,7 +8829,7 @@ If true, a user may send messages in threads in this guild. - If true, a user launch application activites in voice channels in this guild. + If true, a user launch application activities in voice channels in this guild. Creates a new with the provided packed value. @@ -9222,7 +9246,7 @@ If true, a user may send messages in threads in this guild. - If true, a user launch application activites in voice channels in this guild. + If true, a user launch application activities in voice channels in this guild. Creates a new with the provided packed value. @@ -9396,7 +9420,7 @@ If true, a user may send messages in threads in this guild. - If true, a user launch application activites in voice channels in this guild. + If true, a user launch application activities in voice channels in this guild. Creates a new OverwritePermissions with the provided allow and deny packed values. @@ -9892,7 +9916,7 @@ Deletes the current sticker. - The bot neeeds the MANAGE_EMOJIS_AND_STICKERS permission inside the guild in order to delete stickers. + The bot needs the MANAGE_EMOJIS_AND_STICKERS permission inside the guild in order to delete stickers. The options to be used when sending the request. @@ -11189,7 +11213,7 @@ Add multiple reactions to a message. - This method does not bulk add reactions! It will send a request for each reaction inculded. + This method does not bulk add reactions! It will send a request for each reaction included. @@ -11234,7 +11258,7 @@ Sends an inline reply that references a message. - The message that is being replyed on. + The message that is being replied on. The message to be sent. Determines whether the message should be read aloud by Discord or not. The to be sent. @@ -11405,7 +11429,7 @@ Returns a markdown-formatted string with underline formatting. - Returns a markdown-formatted string with strikethrough formatting. + Returns a markdown-formatted string with strike-through formatting. Returns a string with spoiler formatting. @@ -12242,10 +12266,10 @@ - Gets or sets the maximum time to wait for for this request to complete. + Gets or sets the maximum time to wait for this request to complete. - Gets or set the max time, in milliseconds, to wait for for this request to complete. If + Gets or set the max time, in milliseconds, to wait for this request to complete. If null, a request will not time out. If a rate limit has been triggered for this request's bucket and will not be unpaused in time, this request will fail immediately. diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs index cca832874..5b5353999 100644 --- a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs +++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs @@ -81,6 +81,9 @@ namespace Discord /// public List Options { get; set; } - + /// + /// Gets or sets the allowed channel types for this option. + /// + public List ChannelTypes { get; set; } } } diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOption.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOption.cs index fe2a1d597..79bc5bd62 100644 --- a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOption.cs +++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOption.cs @@ -45,5 +45,10 @@ namespace Discord /// If the option is a subcommand or subcommand group type, this nested options will be the parameters. /// IReadOnlyCollection? Options { get; } + + /// + /// The allowed channel types for this option. + /// + IReadOnlyCollection? ChannelTypes { get; } } } diff --git a/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandBuilder.cs index 3dca6a8d6..7402a6e66 100644 --- a/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandBuilder.cs @@ -165,10 +165,12 @@ namespace Discord /// If this option is the default option. /// If this option is set to autocompleate. /// The options of the option to add. + /// The allowed channel types for this option. /// The choices of this option. /// The current builder. public SlashCommandBuilder AddOption(string name, ApplicationCommandOptionType type, - string description, bool? required = null, bool? isDefault = null, bool isAutocomplete = false, List options = null, params ApplicationCommandOptionChoiceProperties[] choices) + string description, bool? required = null, bool? isDefault = null, bool isAutocomplete = false, List options = null, + List channelTypes = null, params ApplicationCommandOptionChoiceProperties[] choices) { // Make sure the name matches the requirements from discord Preconditions.NotNullOrEmpty(name, nameof(name)); @@ -202,7 +204,8 @@ namespace Discord Options = options, Type = type, Autocomplete = isAutocomplete, - Choices = choices != null ? new List(choices) : null + Choices = choices != null ? new List(choices) : null, + ChannelTypes = channelTypes, }; return AddOption(option); @@ -347,6 +350,11 @@ namespace Discord /// public List Options { get; set; } + /// + /// Gets or sets the allowed channel types for this option. + /// + public List ChannelTypes { get; set; } + /// /// Builds the current option. /// @@ -370,7 +378,8 @@ namespace Discord Type = Type, Options = Options?.Count > 0 ? new List(Options.Select(x => x.Build())) : null, Choices = Choices, - Autocomplete = Autocomplete + Autocomplete = Autocomplete, + ChannelTypes = ChannelTypes }; } @@ -384,10 +393,12 @@ namespace Discord /// If this option is the default option. /// If this option supports autocomplete. /// The options of the option to add. + /// The allowed channel types for this option. /// The choices of this option. /// The current builder. public SlashCommandOptionBuilder AddOption(string name, ApplicationCommandOptionType type, - string description, bool? required = null, bool isDefault = false, bool isAutocomplete = false, List options = null, params ApplicationCommandOptionChoiceProperties[] choices) + string description, bool? required = null, bool isDefault = false, bool isAutocomplete = false, List options = null, + List channelTypes = null, params ApplicationCommandOptionChoiceProperties[] choices) { // Make sure the name matches the requirements from discord Preconditions.NotNullOrEmpty(name, nameof(name)); @@ -422,6 +433,7 @@ namespace Discord Options = options, Type = type, Choices = choices != null ? new List(choices) : null, + ChannelTypes = channelTypes, }; return AddOption(option); @@ -510,6 +522,21 @@ namespace Discord return this; } + /// + /// Adds a channnel type to the current option. + /// + /// The to add. + /// The current builder. + public SlashCommandOptionBuilder AddChannelType(ChannelType channelType) + { + if (ChannelTypes == null) + ChannelTypes = new List(); + + ChannelTypes.Add(channelType); + + return this; + } + /// /// Sets the current builders name. /// diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs index 93ee2e9b5..8c617582b 100644 --- a/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs @@ -33,6 +33,9 @@ namespace Discord.API [JsonProperty("autocomplete")] public Optional Autocomplete { get; set; } + [JsonProperty("channel_types")] + public Optional ChannelTypes { get; set; } + public ApplicationCommandOption() { } public ApplicationCommandOption(IApplicationCommandOption cmd) @@ -45,6 +48,8 @@ namespace Discord.API Options = cmd.Options.Select(x => new ApplicationCommandOption(x)).ToArray(); + ChannelTypes = cmd.ChannelTypes.ToArray(); + Required = cmd.Required.HasValue ? cmd.Required.Value : Optional.Unspecified; @@ -78,6 +83,10 @@ namespace Discord.API ? option.Default.Value : Optional.Unspecified; + ChannelTypes = option.ChannelTypes != null + ? option.ChannelTypes.ToArray() + : Optional.Unspecified; + Name = option.Name; Type = option.Type; Description = option.Description; diff --git a/src/Discord.Net.Rest/Discord.Net.Rest.xml b/src/Discord.Net.Rest/Discord.Net.Rest.xml index 2f396dd1b..4352d4f1f 100644 --- a/src/Discord.Net.Rest/Discord.Net.Rest.xml +++ b/src/Discord.Net.Rest/Discord.Net.Rest.xml @@ -2637,7 +2637,7 @@ - Represents a thread channel recieved over REST. + Represents a thread channel received over REST. @@ -2673,7 +2673,7 @@ The id of the user to fetch. The options to be used when sending the request. - A task representing the asyncronous get operation. The task returns a + A task representing the asynchronous get operation. The task returns a if found, otherwise . @@ -2683,7 +2683,7 @@ The options to be used when sending the request. - A task representing the asyncronous get operation. The task returns a + A task representing the asynchronous get operation. The task returns a of 's. @@ -3298,7 +3298,7 @@ The options to be used when sending the request. A task that represents the asynchronous get operation. The task result contains the text channel - where guild notices such as welcome messages and boost events are poste; if none is found. + where guild notices such as welcome messages and boost events are post; if none is found. @@ -3313,11 +3313,11 @@ - Gets the text channel channel where admins and moderators of Community guilds receive notices from Discord. + Gets the text channel where admins and moderators of Community guilds receive notices from Discord. The options to be used when sending the request. - A task that represents the asynchronous get operation. The task result contains the text channel channel where + A task that represents the asynchronous get operation. The task result contains the text channel where admins and moderators of Community guilds receive notices from Discord; if none is set. @@ -3562,7 +3562,7 @@ - Gets this guilds slash commands commands + Gets this guilds slash commands The options to be used when sending the request. @@ -4029,6 +4029,11 @@ A collection of 's for this command. + + + The allowed channel types for this option. + + Represents a Rest-based global application command. @@ -4191,7 +4196,7 @@ Gets the guild that this custom sticker is in. - Note: This property can be if the sticker wasnt fetched from a guild. + Note: This property can be if the sticker wasn't fetched from a guild. @@ -4221,7 +4226,7 @@ - Deletes this object and all of it's childern. + Deletes this object and all of it's children. A task that represents the asynchronous delete operation. @@ -4245,7 +4250,7 @@ A task that represents the asynchronous modification operation. The token used to modify/delete this message expired. - /// Somthing went wrong during the request. + /// Something went wrong during the request. @@ -4254,7 +4259,7 @@ - Deletes this object and all of it's childern. + Deletes this object and all of it's children. A task that represents the asynchronous delete operation. @@ -4278,7 +4283,7 @@ A task that represents the asynchronous modification operation. The token used to modify/delete this message expired. - /// Somthing went wrong during the request. + /// Something went wrong during the request. diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs index 362413c2c..60241c372 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs @@ -39,6 +39,11 @@ namespace Discord.Rest /// public IReadOnlyCollection Options { get; private set; } + /// + /// The allowed channel types for this option. + /// + public IReadOnlyCollection ChannelTypes { get; private set; } + internal RestApplicationCommandOption() { } internal static RestApplicationCommandOption Create(Model model) @@ -67,6 +72,10 @@ namespace Discord.Rest Choices = model.Choices.IsSpecified ? model.Choices.Value.Select(x => new RestApplicationCommandChoice(x)).ToImmutableArray() : ImmutableArray.Create(); + + ChannelTypes = model.ChannelTypes.IsSpecified + ? model.ChannelTypes.Value.ToImmutableArray() + : ImmutableArray.Create(); } #endregion diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml index 5d2b36b91..5086cff49 100644 --- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml +++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml @@ -709,7 +709,7 @@ - Fired when an Interaction is created. This event covers all types of interactions including but not limited to: buttons, select menus, slash commands. + Fired when an Interaction is created. This event covers all types of interactions including but not limited to: buttons, select menus, slash commands, autocompletes. @@ -746,11 +746,11 @@ Fired when a message command is used and its interaction is received. - - - Fired when an autocomplete is used and its interaction is received. - - + + + Fired when an autocomplete is used and its interaction is received. + + Fired when a guild application command is created. @@ -1009,7 +1009,7 @@ - Gets the shard of of this client. + Gets the shard of this client. Gets the current connection state of this client. @@ -1373,7 +1373,7 @@ By default, the Discord gateway will only send offline members if a guild has less than a certain number - of members (determined by in this library). This behaviour is why + of members (determined by in this library). This behavior is why sometimes a user may be missing from the WebSocket cache for collections such as . @@ -2265,7 +2265,7 @@ - Represents a stage channel recieved over the gateway. + Represents a stage channel received over the gateway. @@ -3869,7 +3869,7 @@ - Gets the messagte associated with this message command. + Gets the message associated with this message command. @@ -3927,7 +3927,7 @@ Updates the message which this component resides in with the type A delegate containing the properties to modify the message with. - The request options for this async request. + The request options for this request. A task that represents the asynchronous operation of updating the message. @@ -3944,7 +3944,7 @@ Defers an interaction and responds with type 5 () to send this message ephemerally, otherwise . - The request options for this async request. + The request options for this request. A task that represents the asynchronous operation of acknowledging the interaction. @@ -4056,7 +4056,7 @@ - Gets the current autocomplete option that is activly being filled out. + Gets the current autocomplete option that is actively being filled out. @@ -4081,7 +4081,7 @@ - Represents a Websocket-based recieved by the gateway + Represents a Websocket-based received by the gateway @@ -4189,6 +4189,11 @@ If the option is a subcommand or subcommand group type, this nested options will be the parameters. + + + The allowed channel types for this option. + + Base class for User, Message, and Slash command interactions. @@ -4249,7 +4254,7 @@ - Represents an Interaction recieved over the gateway. + Represents an Interaction received over the gateway. @@ -4920,7 +4925,7 @@ This may return in the WebSocket implementation due to incomplete user collection in - large guilds, or the bot doesnt have the MANAGE_EMOJIS_AND_STICKERS permission. + large guilds, or the bot doesn't have the MANAGE_EMOJIS_AND_STICKERS permission. diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandOption.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandOption.cs index 08b2757cd..836088638 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandOption.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandOption.cs @@ -38,6 +38,11 @@ namespace Discord.WebSocket /// public IReadOnlyCollection Options { get; private set; } + /// + /// The allowed channel types for this option. + /// + public IReadOnlyCollection ChannelTypes { get; private set; } + internal SocketApplicationCommandOption() { } internal static SocketApplicationCommandOption Create(Model model) { @@ -67,6 +72,10 @@ namespace Discord.WebSocket Options = model.Options.IsSpecified ? model.Options.Value.Select(x => SocketApplicationCommandOption.Create(x)).ToImmutableArray() : new ImmutableArray(); + + ChannelTypes = model.ChannelTypes.IsSpecified + ? model.ChannelTypes.Value.ToImmutableArray() + : new ImmutableArray(); } IReadOnlyCollection IApplicationCommandOption.Choices => Choices;