From d6c62335eda529d45b9ed379ea7bd4bb0c431a0e Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Sat, 18 Sep 2021 13:20:50 +0300 Subject: [PATCH 1/3] added deafult permission option to context commands (#155) --- .../ApplicationCommandProperties.cs | 5 +++ .../Context Menus/MessageCommandBuilder.cs | 19 ++++++++- .../Context Menus/UserCommandBuilder.cs | 19 ++++++++- .../Interactions/SlashCommandProperties.cs | 5 --- .../Interactions/InteractionHelper.cs | 42 ++++++++----------- 5 files changed, 59 insertions(+), 31 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs index 2ccb0148b..55c91bc64 100644 --- a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs +++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs @@ -18,6 +18,11 @@ namespace Discord /// public Optional Name { get; set; } + /// + /// Whether the command is enabled by default when the app is added to a guild. Default is + /// + public Optional DefaultPermission { get; set; } + internal ApplicationCommandProperties() { } } } diff --git a/src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandBuilder.cs index 801aca302..ce9c75452 100644 --- a/src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandBuilder.cs @@ -36,6 +36,11 @@ namespace Discord } } + /// + /// Whether the command is enabled by default when the app is added to a guild + /// + public bool DefaultPermission { get; set; } = true; + private string _name { get; set; } /// @@ -49,6 +54,7 @@ namespace Discord MessageCommandProperties props = new MessageCommandProperties() { Name = this.Name, + DefaultPermission = this.DefaultPermission }; return props; @@ -66,6 +72,17 @@ namespace Discord { this.Name = name; return this; - } + } + + /// + /// Sets the default permission of the current command. + /// + /// The default permission value to set. + /// The current builder. + public MessageCommandBuilder WithDefaultPermission (bool value) + { + this.DefaultPermission = value; + return this; + } } } diff --git a/src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandBuilder.cs index 5629a7014..a49250d08 100644 --- a/src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandBuilder.cs @@ -36,6 +36,11 @@ namespace Discord } } + /// + /// Whether the command is enabled by default when the app is added to a guild + /// + public bool DefaultPermission { get; set; } = true; + private string _name { get; set; } /// @@ -47,6 +52,7 @@ namespace Discord UserCommandProperties props = new UserCommandProperties() { Name = this.Name, + DefaultPermission = this.DefaultPermission }; return props; @@ -64,6 +70,17 @@ namespace Discord { this.Name = name; return this; - } + } + + /// + /// Sets the default permission of the current command. + /// + /// The default permission value to set. + /// The current builder. + public UserCommandBuilder WithDefaultPermission (bool value) + { + this.DefaultPermission = value; + return this; + } } } diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommandProperties.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommandProperties.cs index 72c7c322b..e9b7222d4 100644 --- a/src/Discord.Net.Core/Entities/Interactions/SlashCommandProperties.cs +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommandProperties.cs @@ -22,11 +22,6 @@ namespace Discord /// public Optional> Options { get; set; } - /// - /// Whether the command is enabled by default when the app is added to a guild. Default is - /// - public Optional DefaultPermission { get; set; } - internal SlashCommandProperties() { } } } diff --git a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs index a6d8c524b..8bc87339e 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs @@ -68,6 +68,9 @@ namespace Discord.Rest { Name = arg.Name.Value, Type = arg.Type, + DefaultPermission = arg.DefaultPermission.IsSpecified + ? arg.DefaultPermission.Value + : Optional.Unspecified }; if (arg is SlashCommandProperties slashProps) @@ -79,10 +82,6 @@ namespace Discord.Rest model.Options = slashProps.Options.IsSpecified ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() : Optional.Unspecified; - - model.DefaultPermission = slashProps.DefaultPermission.IsSpecified - ? slashProps.DefaultPermission.Value - : Optional.Unspecified; } return await client.ApiClient.CreateGlobalApplicationCommandAsync(model, options).ConfigureAwait(false); @@ -103,6 +102,9 @@ namespace Discord.Rest { Name = arg.Name.Value, Type = arg.Type, + DefaultPermission = arg.DefaultPermission.IsSpecified + ? arg.DefaultPermission.Value + : Optional.Unspecified }; if (arg is SlashCommandProperties slashProps) @@ -114,10 +116,6 @@ namespace Discord.Rest model.Options = slashProps.Options.IsSpecified ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() : Optional.Unspecified; - - model.DefaultPermission = slashProps.DefaultPermission.IsSpecified - ? slashProps.DefaultPermission.Value - : Optional.Unspecified; } models.Add(model); @@ -141,6 +139,9 @@ namespace Discord.Rest { Name = arg.Name.Value, Type = arg.Type, + DefaultPermission = arg.DefaultPermission.IsSpecified + ? arg.DefaultPermission.Value + : Optional.Unspecified }; if (arg is SlashCommandProperties slashProps) @@ -152,10 +153,6 @@ namespace Discord.Rest model.Options = slashProps.Options.IsSpecified ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() : Optional.Unspecified; - - model.DefaultPermission = slashProps.DefaultPermission.IsSpecified - ? slashProps.DefaultPermission.Value - : Optional.Unspecified; } models.Add(model); @@ -202,6 +199,9 @@ namespace Discord.Rest var model = new Discord.API.Rest.ModifyApplicationCommandParams() { Name = args.Name, + DefaultPermission = args.DefaultPermission.IsSpecified + ? args.DefaultPermission.Value + : Optional.Unspecified }; if(args is SlashCommandProperties slashProps) @@ -223,10 +223,6 @@ namespace Discord.Rest model.Options = slashProps.Options.IsSpecified ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() : Optional.Unspecified; - - model.DefaultPermission = slashProps.DefaultPermission.IsSpecified - ? slashProps.DefaultPermission.Value - : Optional.Unspecified; } return await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false); @@ -257,6 +253,9 @@ namespace Discord.Rest { Name = arg.Name.Value, Type = arg.Type, + DefaultPermission = arg.DefaultPermission.IsSpecified + ? arg.DefaultPermission.Value + : Optional.Unspecified }; if (arg is SlashCommandProperties slashProps) @@ -268,10 +267,6 @@ namespace Discord.Rest model.Options = slashProps.Options.IsSpecified ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() : Optional.Unspecified; - - model.DefaultPermission = slashProps.DefaultPermission.IsSpecified - ? slashProps.DefaultPermission.Value - : Optional.Unspecified; } return await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false); @@ -291,6 +286,9 @@ namespace Discord.Rest var model = new ModifyApplicationCommandParams() { Name = arg.Name, + DefaultPermission = arg.DefaultPermission.IsSpecified + ? arg.DefaultPermission.Value + : Optional.Unspecified }; if (arg is SlashCommandProperties slashProps) @@ -302,10 +300,6 @@ namespace Discord.Rest model.Options = slashProps.Options.IsSpecified ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() : Optional.Unspecified; - - model.DefaultPermission = slashProps.DefaultPermission.IsSpecified - ? slashProps.DefaultPermission.Value - : Optional.Unspecified; } return await client.ApiClient.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options).ConfigureAwait(false); From 7d8508d42ec3cd792151706c45acb9b5e528ce07 Mon Sep 17 00:00:00 2001 From: Quin Lynch <49576606+quinchs@users.noreply.github.com> Date: Sat, 18 Sep 2021 15:40:49 -0300 Subject: [PATCH 2/3] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 581c9eecd..dceb2a7a8 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ 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 +If this projects benefits you (*and your financially stable*) consider donating or becoming a sponsor as it really helps out! + ## Known issues 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. From 15a8cf879aafd6f20104933bacdc1ddd7add9322 Mon Sep 17 00:00:00 2001 From: MrCakeSlayer <13650699+MrCakeSlayer@users.noreply.github.com> Date: Sun, 19 Sep 2021 04:01:33 -0400 Subject: [PATCH 3/3] Add note about global commands taking up to an hour to apply to docs (#160) --- .../slash-commands/02-creating-slash-commands.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/guides/interactions/application-commands/slash-commands/02-creating-slash-commands.md b/docs/guides/interactions/application-commands/slash-commands/02-creating-slash-commands.md index 6e4892122..830c52aa5 100644 --- a/docs/guides/interactions/application-commands/slash-commands/02-creating-slash-commands.md +++ b/docs/guides/interactions/application-commands/slash-commands/02-creating-slash-commands.md @@ -12,6 +12,8 @@ Guild commands are specific to the guild you specify when making them. Guild com **Note**: Apps can have a maximum of 100 global commands, and an additional 100 guild-specific commands per guild. +**Note**: Global commands will take up to 1 hour to create, delete or modify on guilds. If you need to update a command quickly for testing you can create it as a guild command. + If you don't have the code for a bot ready yet please follow [this guide](https://docs.stillu.cc/guides/getting_started/first-bot.html). ## SlashCommandBuilder