From c18c799acab7b80324203dbdcc646153fc712cd5 Mon Sep 17 00:00:00 2001 From: Quin Lynch <49576606+quinchs@users.noreply.github.com> Date: Wed, 7 Jul 2021 18:46:34 -0300 Subject: [PATCH 01/10] Update README.md --- docs/guides/slash-commands/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/guides/slash-commands/README.md b/docs/guides/slash-commands/README.md index e69de29bb..702aec6de 100644 --- a/docs/guides/slash-commands/README.md +++ b/docs/guides/slash-commands/README.md @@ -0,0 +1,11 @@ +## Slash command guides + +Here you can find some guides on how to use slash commands. + +1. [Getting started](https://github.com/Discord-Net-Labs/Discord.Net-Labs/blob/Interactions/docs/guides/slash-commands/01-getting-started.md) +2. [Creating a slash command](https://github.com/Discord-Net-Labs/Discord.Net-Labs/blob/Interactions/docs/guides/slash-commands/02-creating-slash-commands.md) +3. [Responding to slash commands](https://github.com/Discord-Net-Labs/Discord.Net-Labs/blob/Interactions/docs/guides/slash-commands/03-responding-to-slash-commands.md) +4. [Parameters in slash commands](https://github.com/Discord-Net-Labs/Discord.Net-Labs/blob/Interactions/docs/guides/slash-commands/04-parameters.md) +5. [Responding ephemerally](https://github.com/Discord-Net-Labs/Discord.Net-Labs/blob/Interactions/docs/guides/slash-commands/05-responding-ephemerally.md) +6. [Subcommands](https://github.com/Discord-Net-Labs/Discord.Net-Labs/blob/Interactions/docs/guides/slash-commands/06-subcommands.md) +7. [Choices](https://github.com/Discord-Net-Labs/Discord.Net-Labs/blob/Interactions/docs/guides/slash-commands/07-choice-slash-command.md) From a50fe6689baf1b120909f6f70d8eb4d847f0b754 Mon Sep 17 00:00:00 2001 From: Quin Lynch <49576606+quinchs@users.noreply.github.com> Date: Wed, 7 Jul 2021 18:48:54 -0300 Subject: [PATCH 02/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f99f3ec4a..e4bb7f5bc 100644 --- a/README.md +++ b/README.md @@ -116,4 +116,4 @@ await Context.Channel.SendMessageAsync("Test selection!", component: builder.Bui > Note: You can only have 5 buttons per row and 5 rows per message. If a row contains a selection dropdown it cannot contain any buttons. ## Slash commands -Slash command example how to's can be found [here](https://github.com/Discord-Net-Labs/Discord.Net-Labs/blob/Interactions/docs/guides/commands/application-commands.md). If you want to read some code using slash commands, you can do that [here](https://github.com/quinchs/SwissbotCore/blob/master/SwissbotCore/Handlers/AutoMod/Censor.cs) +Slash command example how to's can be found [here](https://github.com/Discord-Net-Labs/Discord.Net-Labs/tree/Interactions/docs/guides/slash-commands). If you want to read some code using slash commands, you can do that [here](https://github.com/quinchs/SwissbotCore/blob/master/SwissbotCore/Handlers/AutoMod/Censor.cs) From 8cab0f90e78a0cd2f6c8200429fdde7fe0197d17 Mon Sep 17 00:00:00 2001 From: Quin Lynch <49576606+quinchs@users.noreply.github.com> Date: Wed, 7 Jul 2021 18:56:16 -0300 Subject: [PATCH 03/10] Update 06-subcommands.md --- docs/guides/slash-commands/06-subcommands.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guides/slash-commands/06-subcommands.md b/docs/guides/slash-commands/06-subcommands.md index c4481bfd8..0fd41d12c 100644 --- a/docs/guides/slash-commands/06-subcommands.md +++ b/docs/guides/slash-commands/06-subcommands.md @@ -1,6 +1,6 @@ # Subcommands -Sub commands allow you to have multiple commands available in a single command. They can be useful for representing sub options for a command. for example: a settings command. Let's first look at some limitations with sub commands set by discord. +Subcommands allow you to have multiple commands available in a single command. They can be useful for representing sub options for a command. For example: A settings command. Let's first look at some limitations with subcommands set by discord. - An app can have up to 25 subcommand groups on a top-level command - An app can have up to 25 subcommands within a subcommand group @@ -132,7 +132,7 @@ public async Task Client_Ready() All that code generates a command that looks like this: ![settings](images/settings1.png) -Now that we have our command made, we need to handle the multiple options with this command. so lets add this into our handler +Now that we have our command made, we need to handle the multiple options with this command. So lets add this into our handler: ```cs private async Task Client_InteractionCreated(SocketInteraction arg) @@ -157,7 +157,7 @@ private async Task HandleSettingsCommand(SocketSlashCommand command) // First lets extract our variables var fieldName = command.Data.Options.First().Name; var getOrSet = command.Data.Options.First().Options.First().Name; - // since there is no value on a get command, we use the ? operator because "Options" can be null. + // Since there is no value on a get command, we use the ? operator because "Options" can be null. var value = command.Data.Options.First().Options.First().Options?.FirstOrDefault().Value; switch (fieldName) From 794ae13b1c1976aa83241110d19a2ec9be237ba9 Mon Sep 17 00:00:00 2001 From: Quin Lynch <49576606+quinchs@users.noreply.github.com> Date: Wed, 7 Jul 2021 18:57:04 -0300 Subject: [PATCH 04/10] Update 07-choice-slash-command.md --- docs/guides/slash-commands/07-choice-slash-command.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guides/slash-commands/07-choice-slash-command.md b/docs/guides/slash-commands/07-choice-slash-command.md index 4dbb7b7d3..53cccb39e 100644 --- a/docs/guides/slash-commands/07-choice-slash-command.md +++ b/docs/guides/slash-commands/07-choice-slash-command.md @@ -1,8 +1,8 @@ # Slash Command Choices. -With slash command options you can add choices, making the user select between some set values. Lets create a command that ask how much they like our bot! +With slash command options you can add choices, making the user select between some set values. Lets create a command that asks how much they like our bot! -Lets set up our slash command: +Let's set up our slash command: ```cs private async Task Client_Ready() @@ -78,6 +78,6 @@ private async Task HandleFeedbackCommand(SocketSlashCommand command) } ``` -And this is the result! +And this is the result: ![feedback working](images/feedback2.png) From fa5cc9adafe5459663257f88b7010f2170ce4ab0 Mon Sep 17 00:00:00 2001 From: Quin Lynch <49576606+quinchs@users.noreply.github.com> Date: Thu, 8 Jul 2021 00:21:53 -0300 Subject: [PATCH 05/10] Update 06-subcommands.md --- docs/guides/slash-commands/06-subcommands.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/slash-commands/06-subcommands.md b/docs/guides/slash-commands/06-subcommands.md index 0fd41d12c..5e46406de 100644 --- a/docs/guides/slash-commands/06-subcommands.md +++ b/docs/guides/slash-commands/06-subcommands.md @@ -59,7 +59,7 @@ command |__ subcommand-group ``` -Let's write a settings command that can change 2 fields in our bot. +Let's write a settings command that can change 3 fields in our bot. ```cs public string FieldA { get; set; } = "test"; From 2404143722a05c66f8d044b844610eab2646e3dd Mon Sep 17 00:00:00 2001 From: Quin Lynch <49576606+quinchs@users.noreply.github.com> Date: Thu, 8 Jul 2021 00:23:05 -0300 Subject: [PATCH 06/10] Update 06-subcommands.md --- docs/guides/slash-commands/06-subcommands.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/slash-commands/06-subcommands.md b/docs/guides/slash-commands/06-subcommands.md index 5e46406de..7a3907ff4 100644 --- a/docs/guides/slash-commands/06-subcommands.md +++ b/docs/guides/slash-commands/06-subcommands.md @@ -206,7 +206,7 @@ private async Task HandleSettingsCommand(SocketSlashCommand command) ``` -Now, let't try this out! Running the 3 get commands seems to get the default values we set. +Now, let's try this out! Running the 3 get commands seems to get the default values we set. ![settings get](images/settings2.png) From 3c04b693a74d033e03fcf1dcfd5017111e70b6aa Mon Sep 17 00:00:00 2001 From: Quin Lynch <49576606+quinchs@users.noreply.github.com> Date: Thu, 8 Jul 2021 00:23:21 -0300 Subject: [PATCH 07/10] Update 06-subcommands.md --- docs/guides/slash-commands/06-subcommands.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/slash-commands/06-subcommands.md b/docs/guides/slash-commands/06-subcommands.md index 7a3907ff4..54ff03cdc 100644 --- a/docs/guides/slash-commands/06-subcommands.md +++ b/docs/guides/slash-commands/06-subcommands.md @@ -210,7 +210,7 @@ Now, let's try this out! Running the 3 get commands seems to get the default val ![settings get](images/settings2.png) -Now lets try changing each to a different value. +Now let's try changing each to a different value. ![settings set](images/settings3.png) From e59b83554035ffc10f1b5f6e563ec386299c0da7 Mon Sep 17 00:00:00 2001 From: Quin Lynch <49576606+quinchs@users.noreply.github.com> Date: Fri, 9 Jul 2021 13:35:30 -0300 Subject: [PATCH 08/10] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e4bb7f5bc..fb44c42e3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This repo is a custom fork of Discord.Net that introduces the newest features of discord for testing and experimenting. Nothing here is guaranteed to work but you are more than welcome to submit bugs in the issues tabs ## Known issues -Labs will not work with Playwo's [InteractivityAddon](https://github.com/Playwo/Discord.InteractivityAddon). The reason is that his package depends on the base discord.net lib, you can get around this by cloning his repo and building it with discord.net labs instead of discord.net. +Labs will not work with normal package of Playwo's [InteractivityAddon](https://www.nuget.org/packages/Discord.InteractivityAddon). The reason is that his package depends on the base discord.net lib. You can instead use the [InteractivityAddon.Labs](https://www.nuget.org/packages/Discord.InteractivityAddon.Labs) package which implements some of the features added in Discord.Net-Labs. ## How to use Setting up labs in your project is really simple, here's how to do it: @@ -116,4 +116,4 @@ await Context.Channel.SendMessageAsync("Test selection!", component: builder.Bui > Note: You can only have 5 buttons per row and 5 rows per message. If a row contains a selection dropdown it cannot contain any buttons. ## Slash commands -Slash command example how to's can be found [here](https://github.com/Discord-Net-Labs/Discord.Net-Labs/tree/Interactions/docs/guides/slash-commands). If you want to read some code using slash commands, you can do that [here](https://github.com/quinchs/SwissbotCore/blob/master/SwissbotCore/Handlers/AutoMod/Censor.cs) +Slash command example how to's can be found [here](https://github.com/Discord-Net-Labs/Discord.Net-Labs/blob/Interactions/docs/guides/commands/application-commands.md). If you want to read some code using slash commands, you can do that [here](https://github.com/quinchs/SwissbotCore/blob/master/SwissbotCore/Handlers/AutoMod/Censor.cs) From 2c9958e754728a1ab1da4fe4d4aaaef7f569a661 Mon Sep 17 00:00:00 2001 From: Jared L <48422312+lhjt@users.noreply.github.com> Date: Sat, 10 Jul 2021 03:41:31 +1000 Subject: [PATCH 09/10] Update 03-responding-to-slash-commands.md Updated minor spelling and grammar issues. --- .../slash-commands/03-responding-to-slash-commands.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/guides/slash-commands/03-responding-to-slash-commands.md b/docs/guides/slash-commands/03-responding-to-slash-commands.md index ae836768d..8ab7307d4 100644 --- a/docs/guides/slash-commands/03-responding-to-slash-commands.md +++ b/docs/guides/slash-commands/03-responding-to-slash-commands.md @@ -1,6 +1,6 @@ # Responding to interactions. -Interactions are the base thing sent over by discord. Slash commands are one of the interaction types. In order to receive a slash command we have to listen to the `InteractionCreated` event. Let's add this to our code. +Interactions are the base thing sent over by Discord. Slash commands are one of the interaction types. In order to receive a slash command we have to listen to the `InteractionCreated` event. Let's add this to our code. ```cs client.InteractionCreated += Client_InteractionCreated; @@ -13,7 +13,7 @@ private async Task Client_InteractionCreated(SocketInteraction arg) } ``` -Now that we have the interaction event, Let's talk about the `SocketInteraction` argument. The interaction can be cast to either a `SocketSlashCommand` or a `SocketMessageComponent`. In our case we're trying to use slash commands so Let's cast it to a `SocketSlashCommand`. +Now that we have the interaction event, let's talk about the `SocketInteraction` argument. The interaction can be cast to either a `SocketSlashCommand` or a `SocketMessageComponent`. In our case, we're trying to use slash commands so let's cast it to a `SocketSlashCommand`. ```cs private async Task Client_InteractionCreated(SocketInteraction arg) @@ -25,7 +25,7 @@ private async Task Client_InteractionCreated(SocketInteraction arg) } ``` -With every type of interaction there is a `Data` field. this is where the relevant information lives about our command that was executed. In our case, `Data` is a `SocketSlashCommandData` class. In the data class, we can access the name of the command triggered as well as the options if there were any. For this example, we're just going to respond with the name of the command executed. +With every type of interaction there is a `Data` field. This is where the relevant information lives about our command that was executed. In our case, `Data` is a `SocketSlashCommandData` instance. In the data class, we can access the name of the command triggered as well as the options if there were any. For this example, we're just going to respond with the name of the command executed. ```cs private async Task Client_InteractionCreated(SocketInteraction arg) @@ -45,6 +45,6 @@ Let's try this out! Let's go over the response types quickly, as you would only change them for style points :P -> After receiving an interaction, you must respond to acknowledge it. You can choose to respond with a message immediately using `ChannelMessageWithSource` or you can choose to send a deferred response with `DeferredChannelMessageWithSource`. If choosing a deferred response, the user will see a loading state for the interaction, and you'll have up to 15 minutes to edit the original deferred response using Edit Original Interaction Response. You can read more about Response types [here](https://discord.com/developers/docs/interactions/slash-commands#interaction-response) +> After receiving an interaction, you must respond to acknowledge it. You can choose to respond with a message immediately using `ChannelMessageWithSource` or you can choose to send a deferred response with `DeferredChannelMessageWithSource`. If choosing a deferred response, the user will see a loading state for the interaction, and you'll have up to 15 minutes to edit the original deferred response using Edit Original Interaction Response. You can read more about response types [here](https://discord.com/developers/docs/interactions/slash-commands#interaction-response) This seems to be working! Next, we will look at parameters for slash commands. From 1dd5e97fe67e0e0251b26b6dc014a2615b844077 Mon Sep 17 00:00:00 2001 From: Jared L <48422312+lhjt@users.noreply.github.com> Date: Sat, 10 Jul 2021 04:19:31 +1000 Subject: [PATCH 10/10] Add slash command delete operations - Create `DeleteAllGlobalCommandsAsync` - Create `DeleteSlashCommandsAsync` Co-Authored-By: Quin Lynch <49576606+quinchs@users.noreply.github.com> --- src/Discord.Net.Rest/Discord.Net.Rest.xml | 9 +++++++++ src/Discord.Net.Rest/DiscordRestClient.cs | 3 ++- .../Entities/Guilds/RestGuild.cs | 10 ++++++++++ .../Entities/Interactions/InteractionHelper.cs | 16 +++++++++++++--- .../Discord.Net.WebSocket.xml | 9 +++++++++ .../Entities/Guilds/SocketGuild.cs | 14 ++++++++++++-- 6 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/Discord.Net.Rest/Discord.Net.Rest.xml b/src/Discord.Net.Rest/Discord.Net.Rest.xml index 5a70ac05f..da7b42842 100644 --- a/src/Discord.Net.Rest/Discord.Net.Rest.xml +++ b/src/Discord.Net.Rest/Discord.Net.Rest.xml @@ -2740,6 +2740,15 @@ + + + Deletes all slash commands in the current guild. + + The options to be used when sending the request. + + A task that represents the asynchronous delete operation. + + Gets a collection of slash commands created by the current user in this guild. diff --git a/src/Discord.Net.Rest/DiscordRestClient.cs b/src/Discord.Net.Rest/DiscordRestClient.cs index 0f93c3f65..a8849525e 100644 --- a/src/Discord.Net.Rest/DiscordRestClient.cs +++ b/src/Discord.Net.Rest/DiscordRestClient.cs @@ -125,7 +125,8 @@ namespace Discord.Rest => InteractionHelper.BulkOverwriteGuildCommands(this, guildId, commandProperties, options); public Task> BatchEditGuildCommandPermissions(ulong guildId, IDictionary permissions, RequestOptions options = null) => InteractionHelper.BatchEditGuildCommandPermissionsAsync(this, guildId, permissions, options); - + public Task DeleteAllGlobalCommandsAsync(RequestOptions options = null) + => InteractionHelper.DeleteAllGlobalCommandsAsync(this, options); public Task AddRoleAsync(ulong guildId, ulong userId, ulong roleId) => ClientHelper.AddRoleAsync(this, guildId, userId, roleId); diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index 6c561002e..37491909c 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -256,6 +256,16 @@ namespace Discord.Rest => GuildHelper.LeaveAsync(this, Discord, options); //Interactions + /// + /// Deletes all slash commands in the current guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous delete operation. + /// + public Task DeleteSlashCommandsAsync(RequestOptions options = null) + => InteractionHelper.DeleteAllGuildCommandsAsync(Discord, this.Id, options); + /// /// Gets a collection of slash commands created by the current user in this guild. /// diff --git a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs index 38ba94275..22f12ff48 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs @@ -11,6 +11,16 @@ namespace Discord.Rest { internal static class InteractionHelper { + public static Task DeleteAllGuildCommandsAsync(BaseDiscordClient client, ulong guildId, RequestOptions options = null) + { + return client.ApiClient.BulkOverwriteGuildApplicationCommands(guildId, new CreateApplicationCommandParams[0], options); + } + + public static Task DeleteAllGlobalCommandsAsync(BaseDiscordClient client, RequestOptions options = null) + { + return client.ApiClient.BulkOverwriteGlobalApplicationCommands(new CreateApplicationCommandParams[0], options); + } + public static Task SendInteractionResponse(BaseDiscordClient client, IMessageChannel channel, InteractionResponse response, ulong interactionId, string interactionToken, RequestOptions options = null) { @@ -348,7 +358,7 @@ namespace Discord.Rest return new GuildApplicationCommandPermission(model.Id, model.ApplicationId, guildId, model.Permissions.Select( y => new ApplicationCommandPermission(y.Id, y.Type, y.Permission)).ToArray()); } - catch(HttpException x) + catch (HttpException x) { if (x.HttpCode == System.Net.HttpStatusCode.NotFound) return null; @@ -365,7 +375,7 @@ namespace Discord.Rest List models = new List(); - foreach(var arg in args) + foreach (var arg in args) { var model = new ApplicationCommandPermissions() { @@ -391,7 +401,7 @@ namespace Discord.Rest List models = new List(); - foreach(var arg in args) + foreach (var arg in args) { Preconditions.AtMost(arg.Value.Length, 10, nameof(args)); diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml index 344d7ab20..9df04c8a5 100644 --- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml +++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml @@ -2843,6 +2843,15 @@ voice regions the guild can access. + + + Deletes all slash commands in the current guild. + + The options to be used when sending the request. + + A task that represents the asynchronous delete operation. + + Gets a collection of slash commands created by the current user in this guild. diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index ef4e87305..e8748dda9 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -724,6 +724,16 @@ namespace Discord.WebSocket => GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options); //Interactions + /// + /// Deletes all slash commands in the current guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous delete operation. + /// + public Task DeleteSlashCommandsAsync(RequestOptions options = null) + => InteractionHelper.DeleteAllGuildCommandsAsync(Discord, this.Id, options); + /// /// Gets a collection of slash commands created by the current user in this guild. /// @@ -823,7 +833,7 @@ namespace Discord.WebSocket if (_roles.TryGetValue(model.Id, out SocketRole role)) _roles[model.Id].Update(this.Discord.State, model); else - role = AddRole(model); + role = AddRole(model); return role; } @@ -1289,7 +1299,7 @@ namespace Discord.WebSocket Task> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(VoiceChannels); /// - Task> IGuild.GetCategoriesAsync(CacheMode mode , RequestOptions options) + Task> IGuild.GetCategoriesAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(CategoryChannels); /// Task IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options)