diff --git a/DisCatSharp.Docs/articles/important_changes/ac.md b/DisCatSharp.Docs/articles/important_changes/9_8_2.md similarity index 98% rename from DisCatSharp.Docs/articles/important_changes/ac.md rename to DisCatSharp.Docs/articles/important_changes/9_8_2.md index 8fe7f91e5..7a7b13c38 100644 --- a/DisCatSharp.Docs/articles/important_changes/ac.md +++ b/DisCatSharp.Docs/articles/important_changes/9_8_2.md @@ -1,135 +1,135 @@ --- -uid: important_changes_ac -title: Application Commands +uid: important_changes_9_8_2 +title: Version 9.8.2 --- # What changed? Discord [changed](https://discord.com/developers/docs/interactions/slash-commands) **SlashCommands** into **Application Commands** in favour of the new context menu stuff. You can read about it [here](https://discord.com/developers/docs/interactions/application-commands). ## Upgrade from **DisCatSharp.SlashCommands** to **DisCatSharp.ApplicationCommands** In **DisCatSharp.SlashCommands** you used Application Commands like this: ```cs // Usage directives using DisCatSharp.SlashCommands; using DisCatSharp.SlashCommands.EventArgs; // Extension public static SlashCommandsExtension Slash; // Injecting SlashCommands Client.UseSlashCommands(); Slash = Client.GetSlashCommands(); // Registration of commands and events Slash.SlashCommandErrored += Slash_SlashCommandErrored; Slash.SlashCommandExecuted += Slash_SlashCommandExecuted; Slash.RegisterCommands(); // Events public static Task Slash_SlashCommandExecuted(SlashCommandsExtension sender, SlashCommandExecutedEventArgs e) { Console.WriteLine($"Slash/Info: {e.Context.CommandName}"); return Task.CompletedTask; } public static Task Slash_SlashCommandErrored(SlashCommandsExtension sender, SlashCommandErrorEventArgs e) { Console.WriteLine($"Slash/Error: {e.Exception.Message} | CN: {e.Context.CommandName} | IID: {e.Context.InteractionId}"); return Task.CompletedTask; } // Commands using DisCatSharp; using DisCatSharp.Entities; using DisCatSharp.SlashCommands; using DisCatSharp.SlashCommands.Attributes; namespace TestBot.SlashCommands { internal class Main : SlashCommandModule { [SlashCommand("test", "A slash command made to test the DisCatSharp library!")] public static async Task TestCommand(InteractionContext ctx) { await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource); await Task.Delay(5000); await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("5 second delay complete!")); } } } ``` In **DisCatSharp.ApplicationCommands** you use them like this: ```cs // Usage directives using DisCatSharp.ApplicationCommands; using DisCatSharp.ApplicationCommands.EventArgs; // Extension public static ApplicationCommandsExtension ApplicationCommands; // Injecting SlashCommands Client.UseApplicationCommands(); ApplicationCommands = Client.GetApplicationCommands(); // Registration of commands and events ApplicationCommands.SlashCommandExecuted += Ac_SlashCommandExecuted; ApplicationCommands.SlashCommandErrored += Ac_SlashCommandErrored; /* New stuff - context menu */ ApplicationCommands.ContextMenuExecuted += Ac_ContextMenuExecuted; ApplicationCommands.ContextMenuErrored += Ac_ContextMenuErrored; ApplicationCommands.RegisterCommands(); // Events public static Task Ac_SlashCommandExecuted(ApplicationCommandsExtension sender, SlashCommandExecutedEventArgs e) { Console.WriteLine($"Slash/Info: {e.Context.CommandName}"); return Task.CompletedTask; } public static Task Ac_SlashCommandErrored(ApplicationCommandsExtension sender, SlashCommandErrorEventArgs e) { Console.WriteLine($"Slash/Error: {e.Exception.Message} | CN: {e.Context.CommandName} | IID: {e.Context.InteractionId}"); return Task.CompletedTask; } public static Task Ac_ContextMenuExecuted(ApplicationCommandsExtension sender, ContextMenuExecutedEventArgs e) { Console.WriteLine($"Slash/Info: {e.Context.CommandName}"); return Task.CompletedTask; } public static Task Ac_ContextMenuErrored(ApplicationCommandsExtension sender, ContextMenuErrorEventArgs e) { Console.WriteLine($"Slash/Error: {e.Exception.Message} | CN: {e.Context.CommandName} | IID: {e.Context.InteractionId}"); return Task.CompletedTask; } // Commands using DisCatSharp; using DisCatSharp.Entities; using DisCatSharp.Enums; using DisCatSharp.ApplicationCommands; using DisCatSharp.ApplicationCommands.Attributes; namespace TestBot.ApplicationCommands { internal class Main : ApplicationCommandsModule { [SlashCommand("test", "A slash command made to test the DisCatSharp library!")] public static async Task TestCommand(InteractionContext ctx) { await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource); await Task.Delay(5000); await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("5 second delay complete!")); } } } ``` diff --git a/DisCatSharp.Docs/articles/important_changes/9_8_3.md b/DisCatSharp.Docs/articles/important_changes/9_8_3.md new file mode 100644 index 000000000..35273a842 --- /dev/null +++ b/DisCatSharp.Docs/articles/important_changes/9_8_3.md @@ -0,0 +1,73 @@ +--- +uid: important_changes_9_8_3 +title: Version 9.8.3 +--- + +# What changed? + +We [changed](https://canary.discord.com/channels/858089281214087179/858099438580006913/890973133148926004) the option to restrict channel types in Slash Commands to an extra Attribute named `ChannelTypes` in favour of the application command autocompletion. +You can read about it [here](https://github.com/discord/discord-api-docs/pull/3849). + +## Upgrade from **9.8.2** to **9.8.3** + +In **DisCatSharp.ApplicationComands** you restricted channel types like this: +```cs +[SlashCommand("openstage", "Opens a stage")] +public static async Task OpenStageAsync(InteractionContext ctx, + [Option("stage", "Stage Channel", ChannelType.Stage)] DiscordChannel stage, + [Option("topic", "Topic of stage")] string topic, + [Option("notify", "Whether to notify people")] bool notify = false, + [Option("make_public", "Whether the stage channel will be public")] bool make_public = false) +{ + try + { + await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("Opening stage").AsEphemeral(true)); + await stage.OpenStageAsync(topic, notify, make_public ? StagePrivacyLevel.PUBLIC : StagePrivacyLevel.GUILD_ONLY); + await ctx.EditResponseAsync(new() + { + Content = "Stage channel has been successfully opened." + }); + } + catch (Exception ex) + { + await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(ex.Message + " " + ex.StackTrace)); + } +} +``` + +In **DisCatSharp.ApplicationComands** you restrict channel types now like this: +```cs +[SlashCommand("openstage", "Opens a stage")] +public static async Task OpenStageAsync(InteractionContext ctx, + [Option("stage", "Stage Channel"), ChannelTypes(ChannelType.Stage)] DiscordChannel stage, + [Option("topic", "Topic of stage")] string topic, + [Option("notify", "Whether to notify people")] bool notify = false, + [Option("make_public", "Whether the stage channel will be public")] bool make_public = false) +{ + try + { + await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("Opening stage").AsEphemeral(true)); + await stage.OpenStageAsync(topic, notify, make_public ? StagePrivacyLevel.PUBLIC : StagePrivacyLevel.GUILD_ONLY); + await ctx.EditResponseAsync(new() + { + Content = "Stage channel has been successfully opened." + }); + } + catch (Exception ex) + { + await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(ex.Message + " " + ex.StackTrace)); + } +} +``` + +## New function: Application Command Autocompletion: + +Examples: +> Autocomplete Option: https://github.com/Aiko-IT-Systems/DisCatSharp.Support/blob/main/Commands/Tasks/ConduitTasks.cs#L78 +> Autocomplete Provider: https://github.com/Aiko-IT-Systems/DisCatSharp.Support/blob/main/Providers/ConduitProvider.cs#L108 + +Docs: +https://docs.dcs.aitsys.dev/api/DisCatSharp.ApplicationCommands.Attributes.AutocompleteAttribute.html +https://docs.dcs.aitsys.dev/api/DisCatSharp.ApplicationCommands.Attributes.IAutocompleteProvider.html +https://docs.dcs.aitsys.dev/api/DisCatSharp.Entities.DiscordApplicationCommandAutocompleteChoice.html +https://docs.dcs.aitsys.dev/api/DisCatSharp.ApplicationCommands.OptionAttribute.html#DisCatSharp_ApplicationCommands_OptionAttribute__ctor_System_String_System_String_System_Boolean_ diff --git a/DisCatSharp.Docs/articles/toc.yml b/DisCatSharp.Docs/articles/toc.yml index 867df8aa8..e5b8c0042 100644 --- a/DisCatSharp.Docs/articles/toc.yml +++ b/DisCatSharp.Docs/articles/toc.yml @@ -1,89 +1,91 @@ - name: Preamble href: preamble.md - name: The Basics items: - name: Creating a Bot Account href: basics/bot_account.md - name: Writing Your First Bot href: basics/first_bot.md - name: Beyond Basics items: - name: Events href: beyond_basics/events.md - name: Logging href: beyond_basics/logging/default.md items: - name: The Default Logger href: beyond_basics/logging/default.md - name: Third Party Loggers href: beyond_basics/logging/third_party.md - name: Intents href: beyond_basics/intents.md - name: Sharding href: beyond_basics/sharding.md - name: Message Builder href: beyond_basics/messagebuilder.md - name: Components items: - name: Buttons href: beyond_basics/components/buttons.md - name: Select Menu href: beyond_basics/components/select_menus.md - name: Workarounds href: beyond_basics/workarounds.md - name: Application Commands items: - name: Introduction href: application_commands/intro.md - name: Options href: application_commands/options.md - name: Events href: application_commands/events.md - name: Commands items: - name: Introduction href: commands/intro.md - name: Command Attributes href: commands/command_attributes.md - name: Dependency Injection href: commands/dependency_injection.md - name: Customization items: - name: Help Formatter href: commands/help_formatter.md - name: Argument Converters href: commands/argument_converters.md - name: Command Handler href: commands/command_handler.md - name: Audio items: - name: Lavalink items: - name: Setup href: audio/lavalink/setup.md - name: Configuration href: audio/lavalink/configuration.md - name: Music Commands href: audio/lavalink/music_commands.md - name: VoiceNext items: - name: Prerequisites href: audio/voicenext/prerequisites.md - name: Transmitting href: audio/voicenext/transmit.md - name: Receiving href: audio/voicenext/receive.md - name: Interactivity href: interactivity.md - name: Important Changes items: - - name: Application Commands - href: important_changes/ac.md + - name: Version 9.8.2 + href: important_changes/9_8_2.md + - name: Version 9.8.3 + href: important_changes/9_8_3.md - name: Hosting href: hosting.md - name: Miscellaneous items: - name: Nightly Builds href: misc/nightly_builds.md - name: Reporting Issues href: misc/reporting_issues.md