From 86666610bc1f16538dbb0e9dd7368f7bc7067d28 Mon Sep 17 00:00:00 2001 From: Mewyk Date: Mon, 8 Dec 2025 21:27:03 -0800 Subject: [PATCH 01/10] Remove the old guides --- .../HttpInteractionHandler.cs | 13 - .../HttpInteractions/HttpInteractions.csproj | 13 - .../HttpInteractions/Program.cs | 18 - .../Properties/launchSettings.json | 12 - .../HttpInteractions/appsettings.json | 6 - .../RespondingToInteractions/Program.cs | 104 ------ .../RespondingToInteractions.csproj | 11 - .../basic-concepts/SendingMessages/Program.cs | 314 ----------------- .../SendingMessages/SendingMessages.csproj | 11 - .../guides/basic-concepts/Sharding/Program.cs | 11 - .../Sharding/RegisteringHandlers.cs | 24 -- .../basic-concepts/Sharding/Sharding.csproj | 11 - .../ShardingHosting/MessageUpdateHandler.cs | 12 - .../basic-concepts/ShardingHosting/Program.cs | 12 - .../ShardingHosting/RegisteringHandlers.cs | 27 -- .../ShardingHosting/ShardingHosting.csproj | 16 - .../guides/basic-concepts/Voice/Program.cs | 39 --- .../guides/basic-concepts/Voice/Voice.csproj | 12 - .../basic-concepts/Voice/VoiceModule.cs | 156 --------- .../basic-concepts/http-interactions.md | 53 --- .../installing-native-dependencies.md | 81 ----- .../responding-to-interactions.md | 134 -------- .../guides/basic-concepts/sending-messages.md | 322 ------------------ .../guides/basic-concepts/sharding.md | 44 --- Documentation/guides/basic-concepts/voice.md | 16 - .../events/FirstEvents/FirstEvents.csproj | 11 - .../guides/events/FirstEvents/Program.cs | 22 -- .../FirstEventsHosting.csproj | 16 - .../MessageCreateHandler.cs | 15 - .../MessageReactionAddHandler.cs | 13 - .../events/FirstEventsHosting/Program.cs | 21 -- .../guides/events/Intents/Intents.csproj | 11 - .../guides/events/Intents/Program.cs | 7 - .../IntentsHosting/IntentsHosting.csproj | 16 - .../guides/events/IntentsHosting/Program.cs | 12 - Documentation/guides/events/first-events.md | 43 --- .../getting-started/Coding/Coding.csproj | 11 - .../guides/getting-started/Coding/Program.cs | 11 - .../CodingHosting/CodingHosting.csproj | 16 - .../getting-started/CodingHosting/Program.cs | 12 - .../CodingHosting/appsettings.json | 5 - .../guides/getting-started/making-a-bot.md | 95 ------ .../CustomContexts/CustomCommandContext.cs | 10 - .../CustomContexts/CustomContexts.csproj | 8 - .../CustomContexts/ExampleModule.cs | 15 - .../CustomModuleBases/CustomCommandModule.cs | 14 - .../CustomModuleBases.csproj | 8 - .../CustomModuleBases/ExampleModule.cs | 17 - .../DataAutocompleteProvider.cs | 22 -- .../DependencyInjection/DataModule.cs | 9 - .../DependencyInjection.csproj | 16 - .../DependencyInjection/ISomeService.cs | 11 - .../services/DependencyInjection/Program.cs | 34 -- .../ParameterPreconditions/HelloModule.cs | 9 - .../MustContainAttribute.cs | 18 - .../ParameterPreconditions.csproj | 16 - .../ParameterPreconditions/Program.cs | 28 -- .../Preconditions/AvatarModule.cs | 10 - .../Preconditions/ButtonModule.cs | 9 - .../Preconditions/Preconditions.csproj | 16 - .../Preconditions/Preconditions/Program.cs | 32 -- .../RequireAnimatedAvatarAttribute.cs | 16 - .../Introduction/ExampleModule.cs | 17 - .../Introduction/Introduction.csproj | 12 - .../Introduction/Program.cs | 53 --- .../IntroductionHosting.csproj | 16 - .../IntroductionHosting/Program.cs | 25 -- .../Localizations/AnimalModule.cs | 22 -- .../Localizations/Localizations.csproj | 18 - .../Localizations/Localizations/pl.json | 60 ---- .../Localizations/PermissionsModule.cs | 30 -- .../Localizations/Program.cs | 43 --- .../LocalizationsHosting.csproj | 16 - .../LocalizationsHosting/Program.cs | 20 -- .../MultipleServices/MultipleServices.csproj | 12 - .../MultipleServices/Program.cs | 49 --- .../application-commands/Parameters/Animal.cs | 12 - .../Parameters/ExampleModule.cs | 25 -- .../Parameters/Parameters.csproj | 12 - .../Parameters/Program.cs | 39 --- .../Permissions/ExampleModule.cs | 20 -- .../Permissions/Permissions.csproj | 12 - .../Permissions/Program.cs | 39 --- .../Subcommands/GuildCommandsModule.cs | 29 -- .../Subcommands/Program.cs | 39 --- .../Subcommands/Subcommands.csproj | 12 - .../application-commands/introduction.md | 42 --- .../application-commands/localizations.md | 31 -- .../application-commands/multiple-services.md | 8 - .../application-commands/parameters.md | 47 --- .../application-commands/permissions.md | 4 - .../application-commands/subcommands.md | 7 - .../Introduction/ButtonModule.cs | 9 - .../Introduction/ChannelMenuModule.cs | 9 - .../Introduction/Introduction.csproj | 12 - .../Introduction/MentionableMenuModule.cs | 9 - .../Introduction/ModalModule.cs | 13 - .../Introduction/Program.cs | 48 --- .../Introduction/RoleMenuModule.cs | 9 - .../Introduction/StringMenuModule.cs | 9 - .../Introduction/UserMenuModule.cs | 9 - .../IntroductionHosting.csproj | 16 - .../IntroductionHosting/Program.cs | 35 -- .../Parameters/ExampleModule.cs | 44 --- .../Parameters/Parameters.csproj | 8 - .../component-interactions/introduction.md | 53 --- .../component-interactions/parameters.md | 83 ----- .../custom-module-bases-and-contexts.md | 22 -- .../guides/services/dependency-injection.md | 32 -- Documentation/guides/services/introduction.md | 3 - .../guides/services/preconditions.md | 35 -- .../text-commands/Aliases/Aliases.csproj | 12 - .../text-commands/Aliases/ExampleModule.cs | 9 - .../services/text-commands/Aliases/Program.cs | 36 -- .../Introduction/ExampleModule.cs | 9 - .../Introduction/Introduction.csproj | 12 - .../text-commands/Introduction/Program.cs | 47 --- .../IntroductionHosting.csproj | 16 - .../IntroductionHosting/Program.cs | 21 -- .../IntroductionHosting/appsettings.json | 7 - .../text-commands/Parameters/ExampleModule.cs | 31 -- .../Parameters/Parameters.csproj | 12 - .../text-commands/Parameters/Program.cs | 36 -- .../guides/services/text-commands/aliases.md | 4 - .../services/text-commands/introduction.md | 33 -- .../services/text-commands/parameters.md | 20 -- Documentation/guides/services/type-readers.md | 3 - Documentation/guides/toc.yml | 64 ---- 128 files changed, 3728 deletions(-) delete mode 100644 Documentation/guides/basic-concepts/HttpInteractions/HttpInteractionHandler.cs delete mode 100644 Documentation/guides/basic-concepts/HttpInteractions/HttpInteractions.csproj delete mode 100644 Documentation/guides/basic-concepts/HttpInteractions/Program.cs delete mode 100644 Documentation/guides/basic-concepts/HttpInteractions/Properties/launchSettings.json delete mode 100644 Documentation/guides/basic-concepts/HttpInteractions/appsettings.json delete mode 100644 Documentation/guides/basic-concepts/RespondingToInteractions/Program.cs delete mode 100644 Documentation/guides/basic-concepts/RespondingToInteractions/RespondingToInteractions.csproj delete mode 100644 Documentation/guides/basic-concepts/SendingMessages/Program.cs delete mode 100644 Documentation/guides/basic-concepts/SendingMessages/SendingMessages.csproj delete mode 100644 Documentation/guides/basic-concepts/Sharding/Program.cs delete mode 100644 Documentation/guides/basic-concepts/Sharding/RegisteringHandlers.cs delete mode 100644 Documentation/guides/basic-concepts/Sharding/Sharding.csproj delete mode 100644 Documentation/guides/basic-concepts/ShardingHosting/MessageUpdateHandler.cs delete mode 100644 Documentation/guides/basic-concepts/ShardingHosting/Program.cs delete mode 100644 Documentation/guides/basic-concepts/ShardingHosting/RegisteringHandlers.cs delete mode 100644 Documentation/guides/basic-concepts/ShardingHosting/ShardingHosting.csproj delete mode 100644 Documentation/guides/basic-concepts/Voice/Program.cs delete mode 100644 Documentation/guides/basic-concepts/Voice/Voice.csproj delete mode 100644 Documentation/guides/basic-concepts/Voice/VoiceModule.cs delete mode 100644 Documentation/guides/basic-concepts/http-interactions.md delete mode 100644 Documentation/guides/basic-concepts/installing-native-dependencies.md delete mode 100644 Documentation/guides/basic-concepts/responding-to-interactions.md delete mode 100644 Documentation/guides/basic-concepts/sending-messages.md delete mode 100644 Documentation/guides/basic-concepts/sharding.md delete mode 100644 Documentation/guides/basic-concepts/voice.md delete mode 100644 Documentation/guides/events/FirstEvents/FirstEvents.csproj delete mode 100644 Documentation/guides/events/FirstEvents/Program.cs delete mode 100644 Documentation/guides/events/FirstEventsHosting/FirstEventsHosting.csproj delete mode 100644 Documentation/guides/events/FirstEventsHosting/MessageCreateHandler.cs delete mode 100644 Documentation/guides/events/FirstEventsHosting/MessageReactionAddHandler.cs delete mode 100644 Documentation/guides/events/FirstEventsHosting/Program.cs delete mode 100644 Documentation/guides/events/Intents/Intents.csproj delete mode 100644 Documentation/guides/events/Intents/Program.cs delete mode 100644 Documentation/guides/events/IntentsHosting/IntentsHosting.csproj delete mode 100644 Documentation/guides/events/IntentsHosting/Program.cs delete mode 100644 Documentation/guides/events/first-events.md delete mode 100644 Documentation/guides/getting-started/Coding/Coding.csproj delete mode 100644 Documentation/guides/getting-started/Coding/Program.cs delete mode 100644 Documentation/guides/getting-started/CodingHosting/CodingHosting.csproj delete mode 100644 Documentation/guides/getting-started/CodingHosting/Program.cs delete mode 100644 Documentation/guides/getting-started/CodingHosting/appsettings.json delete mode 100644 Documentation/guides/getting-started/making-a-bot.md delete mode 100644 Documentation/guides/services/CustomModuleBasesAndContexts/CustomContexts/CustomCommandContext.cs delete mode 100644 Documentation/guides/services/CustomModuleBasesAndContexts/CustomContexts/CustomContexts.csproj delete mode 100644 Documentation/guides/services/CustomModuleBasesAndContexts/CustomContexts/ExampleModule.cs delete mode 100644 Documentation/guides/services/CustomModuleBasesAndContexts/CustomModuleBases/CustomCommandModule.cs delete mode 100644 Documentation/guides/services/CustomModuleBasesAndContexts/CustomModuleBases/CustomModuleBases.csproj delete mode 100644 Documentation/guides/services/CustomModuleBasesAndContexts/CustomModuleBases/ExampleModule.cs delete mode 100644 Documentation/guides/services/DependencyInjection/DataAutocompleteProvider.cs delete mode 100644 Documentation/guides/services/DependencyInjection/DataModule.cs delete mode 100644 Documentation/guides/services/DependencyInjection/DependencyInjection.csproj delete mode 100644 Documentation/guides/services/DependencyInjection/ISomeService.cs delete mode 100644 Documentation/guides/services/DependencyInjection/Program.cs delete mode 100644 Documentation/guides/services/Preconditions/ParameterPreconditions/HelloModule.cs delete mode 100644 Documentation/guides/services/Preconditions/ParameterPreconditions/MustContainAttribute.cs delete mode 100644 Documentation/guides/services/Preconditions/ParameterPreconditions/ParameterPreconditions.csproj delete mode 100644 Documentation/guides/services/Preconditions/ParameterPreconditions/Program.cs delete mode 100644 Documentation/guides/services/Preconditions/Preconditions/AvatarModule.cs delete mode 100644 Documentation/guides/services/Preconditions/Preconditions/ButtonModule.cs delete mode 100644 Documentation/guides/services/Preconditions/Preconditions/Preconditions.csproj delete mode 100644 Documentation/guides/services/Preconditions/Preconditions/Program.cs delete mode 100644 Documentation/guides/services/Preconditions/Preconditions/RequireAnimatedAvatarAttribute.cs delete mode 100644 Documentation/guides/services/application-commands/Introduction/ExampleModule.cs delete mode 100644 Documentation/guides/services/application-commands/Introduction/Introduction.csproj delete mode 100644 Documentation/guides/services/application-commands/Introduction/Program.cs delete mode 100644 Documentation/guides/services/application-commands/IntroductionHosting/IntroductionHosting.csproj delete mode 100644 Documentation/guides/services/application-commands/IntroductionHosting/Program.cs delete mode 100644 Documentation/guides/services/application-commands/Localizations/AnimalModule.cs delete mode 100644 Documentation/guides/services/application-commands/Localizations/Localizations.csproj delete mode 100644 Documentation/guides/services/application-commands/Localizations/Localizations/pl.json delete mode 100644 Documentation/guides/services/application-commands/Localizations/PermissionsModule.cs delete mode 100644 Documentation/guides/services/application-commands/Localizations/Program.cs delete mode 100644 Documentation/guides/services/application-commands/LocalizationsHosting/LocalizationsHosting.csproj delete mode 100644 Documentation/guides/services/application-commands/LocalizationsHosting/Program.cs delete mode 100644 Documentation/guides/services/application-commands/MultipleServices/MultipleServices.csproj delete mode 100644 Documentation/guides/services/application-commands/MultipleServices/Program.cs delete mode 100644 Documentation/guides/services/application-commands/Parameters/Animal.cs delete mode 100644 Documentation/guides/services/application-commands/Parameters/ExampleModule.cs delete mode 100644 Documentation/guides/services/application-commands/Parameters/Parameters.csproj delete mode 100644 Documentation/guides/services/application-commands/Parameters/Program.cs delete mode 100644 Documentation/guides/services/application-commands/Permissions/ExampleModule.cs delete mode 100644 Documentation/guides/services/application-commands/Permissions/Permissions.csproj delete mode 100644 Documentation/guides/services/application-commands/Permissions/Program.cs delete mode 100644 Documentation/guides/services/application-commands/Subcommands/GuildCommandsModule.cs delete mode 100644 Documentation/guides/services/application-commands/Subcommands/Program.cs delete mode 100644 Documentation/guides/services/application-commands/Subcommands/Subcommands.csproj delete mode 100644 Documentation/guides/services/application-commands/introduction.md delete mode 100644 Documentation/guides/services/application-commands/localizations.md delete mode 100644 Documentation/guides/services/application-commands/multiple-services.md delete mode 100644 Documentation/guides/services/application-commands/parameters.md delete mode 100644 Documentation/guides/services/application-commands/permissions.md delete mode 100644 Documentation/guides/services/application-commands/subcommands.md delete mode 100644 Documentation/guides/services/component-interactions/Introduction/ButtonModule.cs delete mode 100644 Documentation/guides/services/component-interactions/Introduction/ChannelMenuModule.cs delete mode 100644 Documentation/guides/services/component-interactions/Introduction/Introduction.csproj delete mode 100644 Documentation/guides/services/component-interactions/Introduction/MentionableMenuModule.cs delete mode 100644 Documentation/guides/services/component-interactions/Introduction/ModalModule.cs delete mode 100644 Documentation/guides/services/component-interactions/Introduction/Program.cs delete mode 100644 Documentation/guides/services/component-interactions/Introduction/RoleMenuModule.cs delete mode 100644 Documentation/guides/services/component-interactions/Introduction/StringMenuModule.cs delete mode 100644 Documentation/guides/services/component-interactions/Introduction/UserMenuModule.cs delete mode 100644 Documentation/guides/services/component-interactions/IntroductionHosting/IntroductionHosting.csproj delete mode 100644 Documentation/guides/services/component-interactions/IntroductionHosting/Program.cs delete mode 100644 Documentation/guides/services/component-interactions/Parameters/ExampleModule.cs delete mode 100644 Documentation/guides/services/component-interactions/Parameters/Parameters.csproj delete mode 100644 Documentation/guides/services/component-interactions/introduction.md delete mode 100644 Documentation/guides/services/component-interactions/parameters.md delete mode 100644 Documentation/guides/services/custom-module-bases-and-contexts.md delete mode 100644 Documentation/guides/services/dependency-injection.md delete mode 100644 Documentation/guides/services/introduction.md delete mode 100644 Documentation/guides/services/preconditions.md delete mode 100644 Documentation/guides/services/text-commands/Aliases/Aliases.csproj delete mode 100644 Documentation/guides/services/text-commands/Aliases/ExampleModule.cs delete mode 100644 Documentation/guides/services/text-commands/Aliases/Program.cs delete mode 100644 Documentation/guides/services/text-commands/Introduction/ExampleModule.cs delete mode 100644 Documentation/guides/services/text-commands/Introduction/Introduction.csproj delete mode 100644 Documentation/guides/services/text-commands/Introduction/Program.cs delete mode 100644 Documentation/guides/services/text-commands/IntroductionHosting/IntroductionHosting.csproj delete mode 100644 Documentation/guides/services/text-commands/IntroductionHosting/Program.cs delete mode 100644 Documentation/guides/services/text-commands/IntroductionHosting/appsettings.json delete mode 100644 Documentation/guides/services/text-commands/Parameters/ExampleModule.cs delete mode 100644 Documentation/guides/services/text-commands/Parameters/Parameters.csproj delete mode 100644 Documentation/guides/services/text-commands/Parameters/Program.cs delete mode 100644 Documentation/guides/services/text-commands/aliases.md delete mode 100644 Documentation/guides/services/text-commands/introduction.md delete mode 100644 Documentation/guides/services/text-commands/parameters.md delete mode 100644 Documentation/guides/services/type-readers.md delete mode 100644 Documentation/guides/toc.yml diff --git a/Documentation/guides/basic-concepts/HttpInteractions/HttpInteractionHandler.cs b/Documentation/guides/basic-concepts/HttpInteractions/HttpInteractionHandler.cs deleted file mode 100644 index ba50684b8..000000000 --- a/Documentation/guides/basic-concepts/HttpInteractions/HttpInteractionHandler.cs +++ /dev/null @@ -1,13 +0,0 @@ -using NetCord; -using NetCord.Hosting; - -namespace MyBot; - -public class HttpInteractionHandler(ILogger logger) : IHttpInteractionHandler -{ - public ValueTask HandleAsync(Interaction interaction) - { - logger.LogInformation("Received interaction: {}", interaction); - return default; - } -} diff --git a/Documentation/guides/basic-concepts/HttpInteractions/HttpInteractions.csproj b/Documentation/guides/basic-concepts/HttpInteractions/HttpInteractions.csproj deleted file mode 100644 index ae53d0f85..000000000 --- a/Documentation/guides/basic-concepts/HttpInteractions/HttpInteractions.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - Exe - - - - - - - - - diff --git a/Documentation/guides/basic-concepts/HttpInteractions/Program.cs b/Documentation/guides/basic-concepts/HttpInteractions/Program.cs deleted file mode 100644 index 7415a3d82..000000000 --- a/Documentation/guides/basic-concepts/HttpInteractions/Program.cs +++ /dev/null @@ -1,18 +0,0 @@ -using NetCord.Hosting.AspNetCore; -using NetCord.Hosting.Rest; -using NetCord.Hosting.Services.ApplicationCommands; - -var builder = WebApplication.CreateBuilder(args); - -builder.Services - .AddDiscordRest() - .AddHttpApplicationCommands(); - -var app = builder.Build(); - -app.AddSlashCommand("ping", "Ping!", () => "Pong!"); - -// You can specify any pattern here, but remember to update it in the Discord Developer Portal -app.UseHttpInteractions("/interactions"); - -await app.RunAsync(); diff --git a/Documentation/guides/basic-concepts/HttpInteractions/Properties/launchSettings.json b/Documentation/guides/basic-concepts/HttpInteractions/Properties/launchSettings.json deleted file mode 100644 index e996b6a69..000000000 --- a/Documentation/guides/basic-concepts/HttpInteractions/Properties/launchSettings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "profiles": { - "HttpInteractions": { - "commandName": "Project", - "launchBrowser": false, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "https://localhost:56793" - } - } -} diff --git a/Documentation/guides/basic-concepts/HttpInteractions/appsettings.json b/Documentation/guides/basic-concepts/HttpInteractions/appsettings.json deleted file mode 100644 index e88845212..000000000 --- a/Documentation/guides/basic-concepts/HttpInteractions/appsettings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "Discord": { - "Token": "Token from Discord Developer Portal", - "PublicKey": "Public Key from Discord Developer Portal" - } -} diff --git a/Documentation/guides/basic-concepts/RespondingToInteractions/Program.cs b/Documentation/guides/basic-concepts/RespondingToInteractions/Program.cs deleted file mode 100644 index d1653ea57..000000000 --- a/Documentation/guides/basic-concepts/RespondingToInteractions/Program.cs +++ /dev/null @@ -1,104 +0,0 @@ -using NetCord; -using NetCord.Rest; - -#pragma warning disable IDE0017, IDE0040, IDE0051, IDE0059, CS8321 - -static async Task RespondAsync() -{ - Interaction interaction = null!; - InteractionCallbackProperties callback = null!; - - await interaction.SendResponseAsync(callback); -} - -static void Callbacks() -{ - InteractionCallbackProperties callback; - - callback = InteractionCallback.Message("Here is a sample message interaction callback!"); - - callback = InteractionCallback.DeferredMessage(); - - callback = InteractionCallback.DeferredMessage(MessageFlags.Ephemeral); - - callback = InteractionCallback.DeferredModifyMessage; - - callback = InteractionCallback.ModifyMessage(message => message.Content = "New content!"); - - callback = InteractionCallback.ModifyMessage(message => message.WithContent("New content!")); - - callback = InteractionCallback.Modal(new("intro", "Introduce Yourself") - { - new LabelProperties("First Name", new TextInputProperties("name", TextInputStyle.Short)), - new LabelProperties("Your Bio", new TextInputProperties("bio", TextInputStyle.Paragraph)), - }); - - callback = InteractionCallback.Modal(new ModalProperties("intro", "Introduce Yourself") - .AddComponents( - new LabelProperties("First Name", new TextInputProperties("name", TextInputStyle.Short)), - new LabelProperties("Your Bio", new TextInputProperties("bio", TextInputStyle.Paragraph)))); - - callback = InteractionCallback.Modal(new("intro", "Introduce Yourself") - { - new LabelProperties("First Name", new TextInputProperties("name", TextInputStyle.Short) - { - MinLength = 2, - MaxLength = 32, - Placeholder = "Enter your name", - }), - new LabelProperties("Your Bio", new TextInputProperties("bio", TextInputStyle.Paragraph) - { - MinLength = 10, - Required = false, - Value = "I love programming!", - }), - }); - - callback = InteractionCallback.Modal(new ModalProperties("intro", "Introduce Yourself") - .AddComponents( - new LabelProperties("First Name", new TextInputProperties("name", TextInputStyle.Short) - .WithMinLength(2) - .WithMaxLength(32) - .WithPlaceholder("Enter your name")), - new LabelProperties("Your Bio", new TextInputProperties("bio", TextInputStyle.Paragraph) - .WithMinLength(10) - .WithRequired(false) - .WithValue("I love programming!")))); - - callback = InteractionCallback.Autocomplete([new("Dog", "dog"), new("Cat", "cat")]); - - callback = InteractionCallback.Autocomplete([new("Frog", 0), new("Duck", 1)]); - - callback = InteractionCallback.Autocomplete( - [ - new("Lion", "lion") - { - NameLocalizations = new Dictionary { ["pl"] = "Lew" }, - }, - new("Elephant", "elephant") - { - NameLocalizations = new Dictionary { ["pl"] = "Słoń" }, - }, - ]); - - callback = InteractionCallback.Autocomplete( - [ - new ApplicationCommandOptionChoiceProperties("Lion", "lion") - .WithNameLocalizations(new Dictionary { ["pl"] = "Lew" }), - new ApplicationCommandOptionChoiceProperties("Elephant", "elephant") - .WithNameLocalizations(new Dictionary { ["pl"] = "Słoń" }), - ]); - - callback = InteractionCallback.Pong; -} - -static async Task RespondDeferredAsync() -{ - Interaction interaction = null!; - - await interaction.ModifyResponseAsync(message => message.Content = "The response was modified!"); - - await interaction.ModifyResponseAsync(message => message.WithContent("The response was modified!")); - - await interaction.SendFollowupMessageAsync("The response was provided via follow-up!"); -} diff --git a/Documentation/guides/basic-concepts/RespondingToInteractions/RespondingToInteractions.csproj b/Documentation/guides/basic-concepts/RespondingToInteractions/RespondingToInteractions.csproj deleted file mode 100644 index 559b2b344..000000000 --- a/Documentation/guides/basic-concepts/RespondingToInteractions/RespondingToInteractions.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - Exe - - - - - - - diff --git a/Documentation/guides/basic-concepts/SendingMessages/Program.cs b/Documentation/guides/basic-concepts/SendingMessages/Program.cs deleted file mode 100644 index b00a331ce..000000000 --- a/Documentation/guides/basic-concepts/SendingMessages/Program.cs +++ /dev/null @@ -1,314 +0,0 @@ -using NetCord; -using NetCord.Rest; - -#pragma warning disable IDE0017, IDE0040, IDE0051, IDE0059, CS8321 - -async static Task PropertiesAsync() -{ - IMessageProperties message = null!; - - message.Content = "Hello, World!"; - - message.WithContent("Hello, World!"); - - EmbedProperties embed; - - embed = new() - { - Title = "Welcome to the Baking Club!", - Description = "Join us for delicious recipes and baking tips!", - Url = "https://example.com", - Timestamp = DateTimeOffset.UtcNow, - Color = new(0xFFA500), - Footer = new() - { - Text = "Happy Baking!", - IconUrl = "https://example.com/images/baking-icon.png", - }, - Image = "https://example.com/images/cake.jpg", - Thumbnail = "https://example.com/images/rolling-pin.png", - Author = new() - { - Name = "Baking Club", - Url = "https://example.com", - IconUrl = "https://example.com/images/club-logo.png", - }, - Fields = - [ - new() - { - Name = "Today's Special Recipe", - Value = "Chocolate Lava Cake", - }, - new() - { - Name = "Next Meetup", - Value = "Sunday, 4 PM", - Inline = true, - }, - new() - { - Name = "Location", - Value = "123 Baker's Street", - Inline = true, - }, - new() - { - Name = "Membership Fee", - Value = "Free for the first month!", - Inline = true, - }, - ], - }; - - embed = new EmbedProperties() - .WithTitle("Welcome to the Baking Club!") - .WithDescription("Join us for delicious recipes and baking tips!") - .WithUrl("https://example.com") - .WithTimestamp(DateTimeOffset.UtcNow) - .WithColor(new(0xFFA500)) - .WithFooter(new EmbedFooterProperties() - .WithText("Happy Baking!") - .WithIconUrl("https://example.com/images/baking-icon.png")) - .WithImage("https://example/com/images/cake.jpg") - .WithThumbnail("https://example.com/images/rolling-pin.png") - .WithAuthor(new EmbedAuthorProperties() - .WithName("Baking Club") - .WithUrl("https://example.com") - .WithIconUrl("https://example.com/images/club-logo.png")) - .AddFields( - new EmbedFieldProperties() - .WithName("Today's Special Recipe") - .WithValue("Chocolate Lava Cake"), - new EmbedFieldProperties() - .WithName("Next Meetup") - .WithValue("Sunday, 4 PM") - .WithInline(), - new EmbedFieldProperties() - .WithName("Location") - .WithValue("123 Baker's Street") - .WithInline(), - new EmbedFieldProperties() - .WithName("Membership Fee") - .WithValue("Free for the first month!") - .WithInline()); - - message.Embeds = [embed]; - - message.AddEmbeds(embed); - - message.AllowedMentions = AllowedMentionsProperties.All; - - message.WithAllowedMentions(AllowedMentionsProperties.All); - - message.AllowedMentions = AllowedMentionsProperties.None; - - message.WithAllowedMentions(AllowedMentionsProperties.None); - - message.AllowedMentions = new() - { - Everyone = true, // Allow @everyone and @here - ReplyMention = true, // Allow reply mention - AllowedRoles = [988888771187581010], // Allow specific roles - AllowedUsers = [265546281693347841], // Allow specific users - }; - - message.WithAllowedMentions(new AllowedMentionsProperties() - .WithEveryone() // Allow @everyone and @here - .WithReplyMention() // Allow reply mention - .AddAllowedRoles(988888771187581010) // Allow specific roles - .AddAllowedUsers(265546281693347841)); // Allow specific users - - AttachmentProperties attachment; - - attachment = new AttachmentProperties("hello.txt", new MemoryStream("Hello!"u8.ToArray())); - - attachment = new Base64AttachmentProperties("hello.txt", new MemoryStream("SGVsbG8sIGJhc2U2NCE="u8.ToArray())); - - attachment = new QuotedPrintableAttachmentProperties("polish.txt", - new MemoryStream("R=C3=B3=C5=BCowy means pink"u8.ToArray())); - - TextChannel textChannel = null!; - - HttpClient httpClient = null!; - - // Create a bucket with a file named "hello.txt" - var buckets = await textChannel.CreateGoogleCloudPlatformStorageBucketsAsync([new("hello.txt")]); - - var bucket = buckets[0]; - - // Upload the file content to the bucket - var response = await httpClient.PutAsync(bucket.UploadUrl, new StringContent("Hello, Google!")); - response.EnsureSuccessStatusCode(); - - attachment = new GoogleCloudPlatformAttachmentProperties("hello.txt", bucket.UploadFileName); - - attachment.Title = "Hello, World!"; - attachment.Description = "This is a file named hello.txt"; - - attachment - .WithTitle("Hello, World!") - .WithDescription("This is a file named hello.txt"); - - message.Attachments = [attachment]; - - message.AddAttachments(attachment); - - IMessageComponentProperties component; - - component = new ActionRowProperties - { - new ButtonProperties("welcome", "Welcome", EmojiProperties.Standard("👋"), ButtonStyle.Primary), - new ButtonProperties("hug", EmojiProperties.Custom(356377264209920002), ButtonStyle.Success), - new ButtonProperties("goodbye", "Goodbye", ButtonStyle.Secondary) - { - Disabled = true, - }, - new LinkButtonProperties("https://netcord.dev", "Learn More"), - new PremiumButtonProperties(1271914991536312372), - }; - - component = new ActionRowProperties() - .AddComponents( - new ButtonProperties("welcome", "Welcome", EmojiProperties.Standard("👋"), ButtonStyle.Primary), - new ButtonProperties("hug", EmojiProperties.Custom(356377264209920002), ButtonStyle.Success), - new ButtonProperties("goodbye", "Goodbye", ButtonStyle.Secondary) - .WithDisabled(), - new LinkButtonProperties("https://netcord.dev", "Learn More"), - new PremiumButtonProperties(1271914991536312372)); - - component = new StringMenuProperties("animal") - { - new("Dog", "dog") - { - Default = true, - Emoji = EmojiProperties.Standard("🐶"), - Description = "A loyal companion", - }, - new("Cat", "cat") - { - Emoji = EmojiProperties.Standard("🐱"), - Description = "A curious feline", - }, - new("Bird", "bird") - { - Emoji = EmojiProperties.Standard("🐦"), - Description = "A chirpy flyer", - }, - }; - - component = new StringMenuProperties("animal") - .AddOptions( - new StringMenuSelectOptionProperties("Dog", "dog") - .WithDefault() - .WithEmoji(EmojiProperties.Standard("🐶")) - .WithDescription("A loyal companion"), - new StringMenuSelectOptionProperties("Cat", "cat") - .WithEmoji(EmojiProperties.Standard("🐱")) - .WithDescription("A curious feline"), - new StringMenuSelectOptionProperties("Bird", "bird") - .WithEmoji(EmojiProperties.Standard("🐦")) - .WithDescription("A chirpy flyer")); - - component = new ChannelMenuProperties("channel") - { - DefaultValues = [1124777547687788626], - ChannelTypes = [ChannelType.ForumGuildChannel, ChannelType.PublicGuildThread], - }; - - component = new ChannelMenuProperties("channel") - .AddDefaultValues(1124777547687788626) - .AddChannelTypes(ChannelType.ForumGuildChannel, ChannelType.PublicGuildThread); - - component = new MentionableMenuProperties("mentionable") - { - DefaultValues = - [ - new(803324257194082314, MentionableValueType.User), - ], - }; - - component = new MentionableMenuProperties("mentionable") - .AddDefaultValues( - new MentionableValueProperties(803324257194082314, MentionableValueType.User)); - - component = new RoleMenuProperties("role") - { - DefaultValues = [803169206115237908], - }; - - component = new RoleMenuProperties("role") - .AddDefaultValues(803169206115237908); - - component = new UserMenuProperties("user") - { - DefaultValues = [233590074724319233], - }; - - component = new UserMenuProperties("user") - .AddDefaultValues(233590074724319233); - - message.Components = [component]; - - message.AddComponents(component); - - message.Flags = MessageFlags.SuppressEmbeds | MessageFlags.SuppressNotifications; - - message.WithFlags(MessageFlags.SuppressEmbeds | MessageFlags.SuppressNotifications); -} - -static void Menu() -{ - MenuProperties component = null!; - - component.Placeholder = "Select 2-5 animals"; - component.MinValues = 2; - component.MaxValues = 5; - component.Disabled = true; - - component - .WithPlaceholder("Select 2-5 animals") - .WithMinValues(2) - .WithMaxValues(5) - .WithDisabled(); -} - -static void ImplicitConversion() -{ - MessageProperties message = "Hello, World!"; -} - -static class Classic -{ - static T CreateMessage() where T : IMessageProperties, new() - { - return new() - { - Content = "Hello, World!", - Components = [], - }; - } -} - -static class Fluent -{ - static T CreateMessage() where T : IMessageProperties, new() - { - T message = new(); - - message - .WithContent("Hello, World!") - .WithComponents([]); - - return message; - } - - static void UseCreateMessage() - { - IMessageProperties message; - - message = CreateMessage(); - - message = CreateMessage(); - } -} diff --git a/Documentation/guides/basic-concepts/SendingMessages/SendingMessages.csproj b/Documentation/guides/basic-concepts/SendingMessages/SendingMessages.csproj deleted file mode 100644 index 559b2b344..000000000 --- a/Documentation/guides/basic-concepts/SendingMessages/SendingMessages.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - Exe - - - - - - - diff --git a/Documentation/guides/basic-concepts/Sharding/Program.cs b/Documentation/guides/basic-concepts/Sharding/Program.cs deleted file mode 100644 index 41fdb7e6f..000000000 --- a/Documentation/guides/basic-concepts/Sharding/Program.cs +++ /dev/null @@ -1,11 +0,0 @@ -using NetCord; -using NetCord.Gateway; -using NetCord.Logging; - -ShardedGatewayClient client = new(new BotToken("Token from Discord Developer Portal"), new ShardedGatewayClientConfiguration -{ - LoggerFactory = ShardedConsoleLogger.GetFactory(), -}); - -await client.StartAsync(); -await Task.Delay(-1); diff --git a/Documentation/guides/basic-concepts/Sharding/RegisteringHandlers.cs b/Documentation/guides/basic-concepts/Sharding/RegisteringHandlers.cs deleted file mode 100644 index b6f0caaf3..000000000 --- a/Documentation/guides/basic-concepts/Sharding/RegisteringHandlers.cs +++ /dev/null @@ -1,24 +0,0 @@ -using NetCord; -using NetCord.Gateway; -using NetCord.Logging; - -namespace MyBot; - -internal class RegisteringHandlers -{ - public static async Task RegisterHandlersAsync() - { - ShardedGatewayClient client = new(new BotToken("Token from Discord Developer Portal"), new ShardedGatewayClientConfiguration - { - LoggerFactory = ShardedConsoleLogger.GetFactory(), - }); - - client.MessageUpdate += async (client, message) => - { - await message.ReplyAsync("Message updated!"); - }; - - await client.StartAsync(); - await Task.Delay(-1); - } -} diff --git a/Documentation/guides/basic-concepts/Sharding/Sharding.csproj b/Documentation/guides/basic-concepts/Sharding/Sharding.csproj deleted file mode 100644 index 75d3fd4b9..000000000 --- a/Documentation/guides/basic-concepts/Sharding/Sharding.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - Exe - - - - - - - diff --git a/Documentation/guides/basic-concepts/ShardingHosting/MessageUpdateHandler.cs b/Documentation/guides/basic-concepts/ShardingHosting/MessageUpdateHandler.cs deleted file mode 100644 index 1872e7bef..000000000 --- a/Documentation/guides/basic-concepts/ShardingHosting/MessageUpdateHandler.cs +++ /dev/null @@ -1,12 +0,0 @@ -using NetCord.Gateway; -using NetCord.Hosting.Gateway; - -namespace MyBot; - -public class MessageUpdateHandler : IMessageUpdateShardedGatewayHandler -{ - public async ValueTask HandleAsync(GatewayClient client, Message message) - { - await message.ReplyAsync("Message updated!"); - } -} diff --git a/Documentation/guides/basic-concepts/ShardingHosting/Program.cs b/Documentation/guides/basic-concepts/ShardingHosting/Program.cs deleted file mode 100644 index b5d1a74cc..000000000 --- a/Documentation/guides/basic-concepts/ShardingHosting/Program.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.Extensions.Hosting; - -using NetCord.Hosting.Gateway; - -var builder = Host.CreateApplicationBuilder(args); - -builder.Services - .AddDiscordShardedGateway(); - -var host = builder.Build(); - -await host.RunAsync(); diff --git a/Documentation/guides/basic-concepts/ShardingHosting/RegisteringHandlers.cs b/Documentation/guides/basic-concepts/ShardingHosting/RegisteringHandlers.cs deleted file mode 100644 index e541c563e..000000000 --- a/Documentation/guides/basic-concepts/ShardingHosting/RegisteringHandlers.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Microsoft.Extensions.Hosting; - -using NetCord.Gateway; -using NetCord.Hosting.Gateway; - -namespace MyBot; - -internal class RegisteringHandlers -{ - public static async Task RegisterHandlersAsync(string[] args) - { - var builder = Host.CreateApplicationBuilder(args); - - builder.Services - .AddDiscordShardedGateway(options => - { - options.Intents = GatewayIntents.GuildMessages - | GatewayIntents.DirectMessages - | GatewayIntents.MessageContent; - }) - .AddShardedGatewayHandlers(typeof(Program).Assembly); - - var host = builder.Build(); - - await host.RunAsync(); - } -} diff --git a/Documentation/guides/basic-concepts/ShardingHosting/ShardingHosting.csproj b/Documentation/guides/basic-concepts/ShardingHosting/ShardingHosting.csproj deleted file mode 100644 index e3fb763cf..000000000 --- a/Documentation/guides/basic-concepts/ShardingHosting/ShardingHosting.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - - - - - - - - - - - - diff --git a/Documentation/guides/basic-concepts/Voice/Program.cs b/Documentation/guides/basic-concepts/Voice/Program.cs deleted file mode 100644 index 946bfc027..000000000 --- a/Documentation/guides/basic-concepts/Voice/Program.cs +++ /dev/null @@ -1,39 +0,0 @@ -using NetCord; -using NetCord.Gateway; -using NetCord.Logging; -using NetCord.Rest; -using NetCord.Services; -using NetCord.Services.ApplicationCommands; - -GatewayClient client = new(new BotToken("Token from Discord Developer Portal"), new GatewayClientConfiguration -{ - Intents = GatewayIntents.Guilds | GatewayIntents.GuildVoiceStates, - Logger = new ConsoleLogger(), -}); - -ApplicationCommandService applicationCommandService = new(); -applicationCommandService.AddModules(typeof(Program).Assembly); - -client.InteractionCreate += async interaction => -{ - if (interaction is not ApplicationCommandInteraction applicationCommandInteraction) - return; - - var result = await applicationCommandService.ExecuteAsync(new ApplicationCommandContext(applicationCommandInteraction, client)); - - if (result is not IFailResult failResult) - return; - - try - { - await interaction.SendResponseAsync(InteractionCallback.Message(failResult.Message)); - } - catch - { - } -}; - -await applicationCommandService.RegisterCommandsAsync(client.Rest, client.Id); - -await client.StartAsync(); -await Task.Delay(-1); diff --git a/Documentation/guides/basic-concepts/Voice/Voice.csproj b/Documentation/guides/basic-concepts/Voice/Voice.csproj deleted file mode 100644 index c47a01465..000000000 --- a/Documentation/guides/basic-concepts/Voice/Voice.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - Exe - - - - - - - - diff --git a/Documentation/guides/basic-concepts/Voice/VoiceModule.cs b/Documentation/guides/basic-concepts/Voice/VoiceModule.cs deleted file mode 100644 index 58139a000..000000000 --- a/Documentation/guides/basic-concepts/Voice/VoiceModule.cs +++ /dev/null @@ -1,156 +0,0 @@ -using System.Diagnostics; - -using NetCord; -using NetCord.Gateway.Voice; -using NetCord.Logging; -using NetCord.Rest; -using NetCord.Services.ApplicationCommands; - -namespace MyBot; - -public class VoiceModule : ApplicationCommandModule -{ - [SlashCommand("play", "Plays music", Contexts = [InteractionContextType.Guild])] - public async Task PlayAsync(string track) - { - // Check if the specified track is a well formed uri - if (!Uri.IsWellFormedUriString(track, UriKind.Absolute)) - { - await RespondAsync(InteractionCallback.Message("Invalid track!")); - return; - } - - var guild = Context.Guild!; - - // Get the user voice state - if (!guild.VoiceStates.TryGetValue(Context.User.Id, out var voiceState)) - { - await RespondAsync(InteractionCallback.Message("You are not connected to any voice channel!")); - return; - } - - var client = Context.Client; - - // You should check if the bot is already connected to the voice channel. - // If so, you should use an existing 'VoiceClient' instance instead of creating a new one. - // You also need to add a synchronization here. 'JoinVoiceChannelAsync' should not be used concurrently for the same guild - var voiceClient = await client.JoinVoiceChannelAsync( - guild.Id, - voiceState.ChannelId.GetValueOrDefault(), - new VoiceClientConfiguration - { - Logger = new ConsoleLogger(), - }); - - // Connect - await voiceClient.StartAsync(); - - // Enter speaking state, to be able to send voice - await voiceClient.EnterSpeakingStateAsync(new SpeakingProperties(SpeakingFlags.Microphone)); - - // Respond to the interaction - await RespondAsync(InteractionCallback.Message($"Playing {Path.GetFileName(track)}!")); - - // Create a stream that sends voice to Discord - var outStream = voiceClient.CreateOutputStream(); - - // We create this stream to automatically convert the PCM data returned by FFmpeg to Opus data. - // The Opus data is then written to 'outStream' that sends the data to Discord - OpusEncodeStream stream = new(outStream, PcmFormat.Short, VoiceChannels.Stereo, OpusApplication.Audio); - - ProcessStartInfo startInfo = new("ffmpeg") - { - RedirectStandardOutput = true, - }; - var arguments = startInfo.ArgumentList; - - // Set reconnect attempts in case of a lost connection to 1 - arguments.Add("-reconnect"); - arguments.Add("1"); - - // Set reconnect attempts in case of a lost connection for streamed media to 1 - arguments.Add("-reconnect_streamed"); - arguments.Add("1"); - - // Set the maximum delay between reconnection attempts to 5 seconds - arguments.Add("-reconnect_delay_max"); - arguments.Add("5"); - - // Specify the input - arguments.Add("-i"); - arguments.Add(track); - - // Set the logging level to quiet mode - arguments.Add("-loglevel"); - arguments.Add("-8"); - - // Set the number of audio channels to 2 (stereo) - arguments.Add("-ac"); - arguments.Add("2"); - - // Set the output format to 16-bit signed little-endian - arguments.Add("-f"); - arguments.Add("s16le"); - - // Set the audio sampling rate to 48 kHz - arguments.Add("-ar"); - arguments.Add("48000"); - - // Direct the output to stdout - arguments.Add("pipe:1"); - - // Start the FFmpeg process - var ffmpeg = Process.Start(startInfo)!; - - // Copy the FFmpeg stdout to 'stream', which encodes the voice using Opus and passes it to 'outStream' - await ffmpeg.StandardOutput.BaseStream.CopyToAsync(stream); - - // Flush 'stream' to make sure all the data has been sent and to indicate to Discord that we have finished sending - await stream.FlushAsync(); - } - - [SlashCommand("echo", "Creates echo", Contexts = [InteractionContextType.Guild])] - public async Task EchoAsync() - { - var guild = Context.Guild!; - var userId = Context.User.Id; - - // Get the user voice state - if (!guild.VoiceStates.TryGetValue(userId, out var voiceState)) - return "You are not connected to any voice channel!"; - - var client = Context.Client; - - // You should check if the bot is already connected to the voice channel. - // If so, you should use an existing 'VoiceClient' instance instead of creating a new one. - // You also need to add a synchronization here. 'JoinVoiceChannelAsync' should not be used concurrently for the same guild - var voiceClient = await client.JoinVoiceChannelAsync( - guild.Id, - voiceState.ChannelId.GetValueOrDefault(), - new VoiceClientConfiguration - { - ReceiveHandler = new VoiceReceiveHandler(), // Required to receive voice - Logger = new ConsoleLogger(), - }); - - // Connect - await voiceClient.StartAsync(); - - // Enter speaking state, to be able to send voice - await voiceClient.EnterSpeakingStateAsync(new SpeakingProperties(SpeakingFlags.Microphone)); - - // Create a stream that sends voice to Discord - var outStream = voiceClient.CreateOutputStream(normalizeSpeed: false); - - voiceClient.VoiceReceive += args => - { - // Pass current user voice directly to the output to create echo - if (voiceClient.Cache.Users.TryGetValue(args.Ssrc, out var voiceUserId) && voiceUserId == userId) - outStream.Write(args.Frame); - return default; - }; - - // Return the response - return "Echo!"; - } -} diff --git a/Documentation/guides/basic-concepts/http-interactions.md b/Documentation/guides/basic-concepts/http-interactions.md deleted file mode 100644 index f20752f68..000000000 --- a/Documentation/guides/basic-concepts/http-interactions.md +++ /dev/null @@ -1,53 +0,0 @@ ---- -omitAppTitle: true -title: Handling Discord HTTP Interactions with C# and ASP.NET Core -description: Learn how to make your Discord bot receive interactions from Discord via HTTP requests using the NetCord.Hosting.AspNetCore package in C# and ASP.NET Core. ---- - -# Handling HTTP Interactions with ASP.NET Core - -This guide will show you how to receive and handle Discord interactions, like slash commands and button clicks, through HTTP requests using the [NetCord.Hosting.AspNetCore](https://www.nuget.org/packages/NetCord.Hosting.AspNetCore) package. This ASP.NET Core package can be effortlessly integrated with [NetCord.Hosting.Services](https://www.nuget.org/packages/NetCord.Hosting.Services) to handle these HTTP interactions in C# easily. Additionally, you can implement your own @NetCord.Hosting.IHttpInteractionHandler to manually handle HTTP interactions received from Discord, giving you full control over your bot's behavior. - -## Required Dependencies - -Before you get started, ensure that you've installed the necessary native dependencies. Follow the [installation guide](installing-native-dependencies.md) to set them up. - -## Setting Up HTTP Interactions in C# - -To handle HTTP interactions from Discord in your bot, you need to use @NetCord.Hosting.Rest.RestClientServiceCollectionExtensions.AddDiscordRest* to add the @NetCord.Rest.RestClient and then call @NetCord.Hosting.AspNetCore.EndpointRouteBuilderExtensions.UseHttpInteractions* to map the HTTP interactions route. You can also use @NetCord.Hosting.Services.ApplicationCommands.ApplicationCommandServiceServiceCollectionExtensions.AddHttpApplicationCommands* to add the application command service with preconfigured HTTP contexts to your host builder. -[!code-cs[Program.cs](HttpInteractions/Program.cs?highlight=8,16)] - -### Receiving HTTP Interactions via HTTP Interaction Handler - -You can also create your own @NetCord.Hosting.IHttpInteractionHandler to handle HTTP interactions manually. This allows you to have full control over the behavior of your bot when receiving HTTP interactions. You register them using @"NetCord.Hosting.HttpInteractionHandlerServiceCollectionExtensions.AddHttpInteractionHandler``1(Microsoft.Extensions.DependencyInjection.IServiceCollection)?text=AddHttpInteractionHandler". - -[!code-cs[HttpInteractionHandler.cs](HttpInteractions/HttpInteractionHandler.cs#L6-L14)] - -## Configuring Your Discord Bot for HTTP Interactions - -To make your bot receive HTTP interactions from Discord, you need to store the public key in the configuration and specify the endpoint URL in the [Discord Developer Portal](https://discord.com/developers/applications). - -![Shows 'Public Key' section in 'General Information' section](../../images/http-interactions_FindingPublicKeyAndSpecifyingInteractionEndpointUrl.webp){width=850px} - -### Specifying the Public Key in the Configuration - -You can for example use `appsettings.json` file for configuration. It should look like this: -[!code-json[appsettings.json](HttpInteractions/appsettings.json?highlight=4)] - -### Specifying the Interactions Endpoint URL - -If your bot is hosted at `https://example.com` and you have specified `/interactions` pattern in @NetCord.Hosting.AspNetCore.EndpointRouteBuilderExtensions.UseHttpInteractions*, the endpoint URL will be `https://example.com/interactions`. Also note that Discord sends validation requests to the endpoint URL, so your bot must be running while updating it. - -For local testing, you can use [ngrok](https://ngrok.com), a tool that exposes your local server to the internet, providing a public URL to receive interactions. Use the following command to start ngrok with a correct port specified: -```bash -ngrok http http://localhost:port -``` - -It will generate a URL that you can use to receive HTTP interactions from Discord. For example, if the URL is `https://random-subdomain.ngrok-free.app` and you have specified `/interactions` pattern in @NetCord.Hosting.AspNetCore.EndpointRouteBuilderExtensions.UseHttpInteractions*, the endpoint URL will be `https://random-subdomain.ngrok-free.app/interactions`. - -## Extending Your HTTP Interactions Bot - -Now, as you have your bot up and running, you can start adding more features to it. You can use the following guides to learn more about the features you can add to your HTTP interactions based bot: - -- **@"application-commands?text=Application Commands":** Learn how to make complex commands with parameters and subcommands with ease. -- **@"component-interactions?text=Component Interactions":** Make your HTTP interactions bot interactive with buttons, select menus, and other components easily. diff --git a/Documentation/guides/basic-concepts/installing-native-dependencies.md b/Documentation/guides/basic-concepts/installing-native-dependencies.md deleted file mode 100644 index 3baf8305a..000000000 --- a/Documentation/guides/basic-concepts/installing-native-dependencies.md +++ /dev/null @@ -1,81 +0,0 @@ -# Installing Native Dependencies - -This is a hidden guide that is not visible in the guides index! If you are reading this, you are probably looking for information on how to install native dependencies for HTTP interactions or voice. - -## HTTP Interactions - -For HTTP interactions, [Libsodium](https://doc.libsodium.org/installation) is required. - -## Voice - -For voice: -- [Libsodium](https://doc.libsodium.org/installation) **is not generally** required, but it **is highly recommended for production bots**. It is caused by the fact that generally @NetCord.Gateway.Voice.Encryption.Aes256GcmRtpSizeEncryption, which does not require Libsodium, is supported by Discord and is used by default. However, there is a small chance that Discord will not support this encryption mode for your connection. In this case, @NetCord.Gateway.Voice.Encryption.XChaCha20Poly1305RtpSizeEncryption, which does require Libsodium, is used by default. Libsodium is required when you use @NetCord.Gateway.Voice.Encryption.XChaCha20Poly1305RtpSizeEncryption, @NetCord.Gateway.Voice.Encryption.XSalsa20Poly1305Encryption, @NetCord.Gateway.Voice.Encryption.XSalsa20Poly1305LiteEncryption, @NetCord.Gateway.Voice.Encryption.XSalsa20Poly1305LiteRtpSizeEncryption, or @NetCord.Gateway.Voice.Encryption.XSalsa20Poly1305SuffixEncryption. -- [Opus](https://opus-codec.org/downloads) is only required when you are using `Opus` prefixed classes. - -## Installation - -### [Dynamic Linking](#tab/dynamic) - -For dynamic linking, you can install Libsodium for the most popular platforms by referencing the [official Libsodium NuGet package](https://www.nuget.org/packages/libsodium). - -### Manual or System-wide Installation - -#### Windows - -For dynamic linking on Windows, you need to use the dynamic link libraries (`libsodium` and/or `opus`). Here's how to set it up: -- Download or build the dynamic link libraries (`libsodium` and/or `opus`) compatible with your development environment. -- Place these files in the runtime directory of your application. This is the folder where your application's executable is located. - -#### Linux and MacOS - -Dynamic linking on Linux and MacOS involves using shared libraries (`libsodium` and/or `opus`). You can install them using your system's package manager if available or follow these steps to install them manually: -- Download or build the shared libraries (`libsodium` and/or `opus`) that are compatible with your development environment. -- Place these files in the runtime directory of your application, which is the folder where your application's executable is located. - -### [Static Linking](#tab/static) - -> [!NOTE] -> Static linking requires [Native AOT](https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot) compilation. - -#### Windows - -When using static linking on Windows, you need to link to the static libraries (`libsodium` and/or `opus`). Here are the steps to set up static linking in your application: -- Download or build the static libraries (`libsodium` and/or `opus`) compatible with your development environment. -- Link these libraries in your project settings. Ensure that you specify the correct paths to these libraries: - ```xml - - - - - - - - ``` - -You don't need to place any of these files in the runtime directory, as static linking embeds the library code directly into your application, eliminating the need for separate files. - -#### Linux and MacOS - -Static linking on Linux and MacOS involves linking your application with the static libraries (`libsodium` and/or `opus`). You can install them using your system's package manager if available or download or build the static libraries (`libsodium` and/or `opus`) compatible with your development environment manually. - -Link these libraries in your project settings. Make sure you specify the correct paths to these libraries: -```xml - - - - - - - -``` - -Since you're statically linking, you won't need to place any of these files in the runtime directory. The necessary code from the libraries will be included directly in your application. - -*** - -#### Installation External Links - -| Library | Installation Link | -|-----------|----------------------------------------| -| Libsodium | https://doc.libsodium.org/installation | -| Opus | https://opus-codec.org/downloads | diff --git a/Documentation/guides/basic-concepts/responding-to-interactions.md b/Documentation/guides/basic-concepts/responding-to-interactions.md deleted file mode 100644 index 3409b5083..000000000 --- a/Documentation/guides/basic-concepts/responding-to-interactions.md +++ /dev/null @@ -1,134 +0,0 @@ ---- -uid: responding-to-interactions -omitAppTitle: true -title: Responding to Interactions in C# Discord Bots with NetCord -description: Learn to handle interactions in your C# Discord bot with NetCord. Explore response types like messages, modals, and deferrals for building bots with .NET. ---- - -# Responding to Interactions - -This guide explains how to handle interactions and prepare appropriate responses. - -To create a response, use the @NetCord.Rest.InteractionCallback class. It supports various response types, such as messages, modals, and autocomplete suggestions. Once created, the callback must be passed to the @"NetCord.Interaction.SendResponseAsync*?text=Interaction.SendResponseAsync" method to send it to Discord. - -[!code-cs[Sample response](RespondingToInteractions/Program.cs#L11)] - -The [NetCord.Services](https://www.nuget.org/packages/NetCord.Services) package provides additional utilities to simplify this process. - -## Responding with a Message - -You can respond with a message by using @"NetCord.Rest.InteractionCallback.Message*?text=InteractionCallback.Message". - -[!code-cs[Responding with a message](RespondingToInteractions/Program.cs#L18)] - -For advanced message options, see @"sending-messages?text=Sending Messages". - -## Responding with Deferral - -Deferring is useful when performing long-running operations before sending a message. Deferrals give you up to 15 minutes to complete the operation. After deferring, you can either modify the initial response (the deferral) or send a follow-up message, both work the same way. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Responding after deferral](RespondingToInteractions/Program.cs#L99)] - -[!code-cs[Responding after deferral](RespondingToInteractions/Program.cs#L103)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Responding after deferral](RespondingToInteractions/Program.cs#L101)] - -[!code-cs[Responding after deferral](RespondingToInteractions/Program.cs#L103)] - -*** - -The [NetCord.Services](https://www.nuget.org/packages/NetCord.Services) package also provides shortcuts for deferral handling. - -For advanced message options, see @"sending-messages?text=Sending Messages". - -### Deferred Message - -For application commands, use @"NetCord.Rest.InteractionCallback.DeferredMessage*?text=InteractionCallback.DeferredMessage" to send a deferral response. This shows a loading state to the user while you prepare the message. - -[!code-cs[Responding with a deferred message](RespondingToInteractions/Program.cs#L20)] - -You can specify @"NetCord.MessageFlags.Ephemeral?text=MessageFlags.Ephemeral" to make the response visible only to the user who triggered the interaction. - -[!code-cs[Responding with a deferred message](RespondingToInteractions/Program.cs#L22)] - -### Deferred Modify Message - -For component interactions, use @"NetCord.Rest.InteractionCallback.DeferredModifyMessage?text=InteractionCallback.DeferredModifyMessage". This type of deferral doesn't display a loading state to the user. - -[!code-cs[Responding with a deferred modify message](RespondingToInteractions/Program.cs#L24)] - -## Responding with Message Modification - -For message component interactions, you can modify the message they are attached to using @"NetCord.Rest.InteractionCallback.ModifyMessage*?text=InteractionCallback.ModifyMessage". - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Responding with a modify message](RespondingToInteractions/Program.cs#L26)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Responding with a modify message](RespondingToInteractions/Program.cs#L28)] - -*** - -## Responding with a Modal - -Modals are interactive forms users can fill out. Use @"NetCord.Rest.InteractionCallback.Modal*?text=InteractionCallback.Modal" to create a modal callback. Each modal can include up to five components. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Responding with a modal](RespondingToInteractions/Program.cs#L30-L34)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Responding with a modal](RespondingToInteractions/Program.cs#L36-L39)] - -*** - -It is also supported to provide additional options for each input, such as placeholder text, default value, and whether the input is required. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Responding with a modal](RespondingToInteractions/Program.cs#L41-L55)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Responding with a modal](RespondingToInteractions/Program.cs#L57-L66)] - -*** - -## Responding with Autocomplete - -Autocomplete provides a list of options while the user types a slash command. Use @"NetCord.Rest.InteractionCallback.Autocomplete*?text=InteractionCallback.Autocomplete" to respond to autocomplete interactions. - -For string parameters: - -[!code-cs[Responding with autocomplete](RespondingToInteractions/Program.cs#L68)] - -For numeric parameters: - -[!code-cs[Responding with autocomplete](RespondingToInteractions/Program.cs#L70)] - -It is also supported to provide name localizations for each option. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Responding with autocomplete](RespondingToInteractions/Program.cs#L72-L82)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Responding with autocomplete](RespondingToInteractions/Program.cs#L84-L90)] - -*** - -## Responding with a Pong - -A "pong" callback is used to respond to ping HTTP interactions sent by Discord to verify the endpoint's availability. Use @"NetCord.Rest.InteractionCallback.Pong?text=InteractionCallback.Pong" to create this response. - -[!code-cs[Responding with a pong](RespondingToInteractions/Program.cs#L92)] - -If you're using the [NetCord.Hosting.AspNetCore](https://www.nuget.org/packages/NetCord.Hosting.AspNetCore) package, these ping interactions are handled automatically, and you don't need to provide the callback manually. diff --git a/Documentation/guides/basic-concepts/sending-messages.md b/Documentation/guides/basic-concepts/sending-messages.md deleted file mode 100644 index 87d09ea00..000000000 --- a/Documentation/guides/basic-concepts/sending-messages.md +++ /dev/null @@ -1,322 +0,0 @@ ---- -uid: sending-messages -omitAppTitle: true -title: Sending Messages in a C# Discord Bot with NetCord Library -description: Learn how to send messages in a C# Discord bot using NetCord, covering text, embeds, attachments, allowed mentions, and interactive components like buttons. ---- - -# Sending Messages - -This guide demonstrates how to send messages to a channel. - -Different types of message properties are available because various endpoints support different options. However, all these types implement @NetCord.Rest.IMessageProperties, which defines the properties supported by all endpoints. This guide will cover the properties defined in @NetCord.Rest.IMessageProperties. - -## Types of Message Properties - -The following message properties types are available: -- @NetCord.Rest.MessageProperties - Can be used with @"NetCord.Rest.RestClient.SendMessageAsync*?text=RestClient.SendMessageAsync" to send messages to channels. -- @NetCord.Rest.InteractionMessageProperties - Used for sending messages in response to interactions. Refer to @"responding-to-interactions?text=Responding to Interactions#responding-with-a-message" for more information. -- @NetCord.Rest.ReplyMessageProperties - Can be used with @"NetCord.Rest.RestMessage.ReplyAsync*?text=RestMessage.ReplyAsync" to reply to messages. -- @NetCord.Rest.WebhookMessageProperties - Can be used with @"NetCord.Rest.RestClient.ExecuteWebhookAsync*?text=RestClient.ExecuteWebhookAsync" to send messages via webhooks. -- @NetCord.Rest.ForumGuildThreadMessageProperties - Can be used with @"NetCord.Rest.RestClient.CreateForumGuildThreadAsync*?text=RestClient.CreateForumGuildThreadAsync" to create forum posts. - -All the @NetCord.Rest.RestClient methods mentioned above have their equivalent methods in appropriate objects, such as @NetCord.TextChannel and @NetCord.Rest.WebhookClient. - -## Using @NetCord.Rest.IMessageProperties - -If you need to build an API that supports creating messages for multiple endpoints, you can utilize the @NetCord.Rest.IMessageProperties interface. This allows you to define the properties common to all message properties types in a straightforward manner. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Using 'IMessageProperties'](SendingMessages/Program.cs#L283-L290)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Using 'IMessageProperties'](SendingMessages/Program.cs#L295-L304)] - -*** - -You can view sample usages of this method below: - -[!code-cs[Using our API for 'MessageProperties'](SendingMessages/Program.cs#L310)] -[!code-cs[Using our API for 'InteractionMessageProperties'](SendingMessages/Program.cs#L312)] - -## Defining the Content - -The content refers to the main text of the message. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Defining the content](SendingMessages/Program.cs#L10)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Defining the content](SendingMessages/Program.cs#L12)] - -*** - -All message properties types support an implicit conversion from a string. However, note that this does not apply to @NetCord.Rest.IMessageProperties, as it is an interface. - -[!code-cs[Implicit conversion from string](SendingMessages/Program.cs#L278)] - -## Adding Embeds - -Embeds are rich content elements that can be attached to a message. They support titles, descriptions, images, and more. A message can include up to 10 embeds. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Adding embeds](SendingMessages/Program.cs#L96)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Adding embeds](SendingMessages/Program.cs#L98)] - -*** - -### Customizing Embeds - -You can customize embeds by specifying properties such as the title, description, color, and image. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Customizing embeds](SendingMessages/Program.cs#L16-L62)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Customizing embeds](SendingMessages/Program.cs#L64-L94)] - -*** - -## Managing Allowed Mentions - -Allowed mentions define which users and roles can be mentioned within the message. - -To allow all mentions, use @"NetCord.Rest.AllowedMentionsProperties.All?text=AllowedMentionsProperties.All". - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Setting allowed mentions](SendingMessages/Program.cs#L100)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Setting allowed mentions](SendingMessages/Program.cs#L102)] - -*** - -To disable all mentions, use @"NetCord.Rest.AllowedMentionsProperties.None?text=AllowedMentionsProperties.None". - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Setting allowed mentions](SendingMessages/Program.cs#L104)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Setting allowed mentions](SendingMessages/Program.cs#L106)] - -*** - -You can also define custom allowed mentions. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Customizing allowed mentions](SendingMessages/Program.cs#L108-L114)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Customizing allowed mentions](SendingMessages/Program.cs#L116-L120)] - -*** - -## Attaching Files - -Attachments are files that can be added to a message. A message can contain up to 10 attachments. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Adding attachments](SendingMessages/Program.cs#L153)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Adding attachments](SendingMessages/Program.cs#L155)] - -*** - -### Customizing Attachments - -Attachments are files that can be added to a message, with up to 10 attachments per message. All attachment types support any readable stream, such as file streams. Below are examples of how you can create and customize attachments. - -#### Standard Attachments - -This is an example of a standard attachment. The following code creates an attachment with the content "Hello!". - -[!code-cs[Creating attachments](SendingMessages/Program.cs#L124)] - -#### Base64-Encoded Attachments - -You can create an attachment with base64 encoding. The following example demonstrates an attachment that will display "Hello, base64!" in the chat. - -[!code-cs[Base64 attachment](SendingMessages/Program.cs#L126)] - -#### Quoted-Printable Attachments - -Quoted-printable encoding is another supported format. The following example creates an attachment that will display "Różowy means pink" in the chat. - -[!code-cs[Quoted-printable attachment](SendingMessages/Program.cs#L128-L129)] - -#### Google Cloud Attachments - -> [!WARNING] -> Discord does not offer any stability guarantees for this feature so it can break without notice. - -Discord supports uploading attachments directly to Google Cloud Platform. This example creates an attachment uploaded directly to Google Cloud Platform with the content "Hello, Google!". - -[!code-cs[Google Cloud attachment](SendingMessages/Program.cs#L135-L144)] - -#### Adding Titles and Descriptions - -You can enhance your attachments by adding titles and descriptions. Use the `AttachmentProperties.Title` and `AttachmentProperties.Description` properties to set these values. Here's an example: - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Attachment properties](SendingMessages/Program.cs#L146-L147)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Attachment properties](SendingMessages/Program.cs#L149-L151)] - -*** - -## Adding Components - -Components are interactive elements that can be attached to a message. These include buttons, select menus, and more. A message can contain up to 5 components, including action rows and select menus. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Adding components](SendingMessages/Program.cs#L251)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Adding components](SendingMessages/Program.cs#L253)] - -*** - -### Action Rows - -Action rows contain buttons, and each can have up to 5 buttons. Available button types include: -- @NetCord.Rest.ButtonProperties, which triggers an interaction when clicked. -- @NetCord.Rest.LinkButtonProperties, which opens a URL when clicked. -- @NetCord.Rest.PremiumButtonProperties, which prompts the user to pay when clicked. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Defining action rows](SendingMessages/Program.cs#L159-L169)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Defining action rows](SendingMessages/Program.cs#L171-L178)] - -*** - -### Select Menus - -Select menus are dropdown menus containing up to 25 options. They support various types, such as strings, channels, and users. - -#### String Menus - -String menus allow you to include any string options. Each option in the menu can be customized with additional properties, such as setting a default selection, adding an emoji, or providing a description for better context. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Creating string menus](SendingMessages/Program.cs#L180-L198)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Creating string menus](SendingMessages/Program.cs#L200-L211)] - -*** - -#### Channel Menus - -Channel menus include channels as options, and support filtering by channel type and the ability to specify default channels. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Creating channel menus](SendingMessages/Program.cs#L213-L217)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Creating channel menus](SendingMessages/Program.cs#L219-L221)] - -*** - -#### Mentionable Menus - -Mentionable menus include users and roles as options, and support specifying default users and roles. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Creating mentionable menus](SendingMessages/Program.cs#L223-L229)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Creating mentionable menus](SendingMessages/Program.cs#L231-L233)] - -*** - -#### Role Menus - -Role menus contain roles as options, and support specifying default roles. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Creating role menus](SendingMessages/Program.cs#L235-L238)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Creating role menus](SendingMessages/Program.cs#L240-L241)] - -*** - -#### User Menus - -User menus allow selecting users as options, and support specifying default users. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Creating user menus](SendingMessages/Program.cs#L243-L246)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Creating user menus](SendingMessages/Program.cs#L248-L249)] - -*** - -#### Specifying Additional Properties - -Additionally, all select menus allow you to specify a placeholder, set a minimum and maximum number of selectable options, and disable the select menu if necessary. - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Configuring select menus](SendingMessages/Program.cs#L264-L267)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Configuring select menus](SendingMessages/Program.cs#L269-L273)] - -*** - -## Configuring Flags - -Flags control how a message behaves. You can combine multiple flags using the bitwise OR operator. - -For example, this configuration specifies that no embeds from URLs should be displayed, and the message should be silent (not triggering push or desktop notifications). - -# [Classic Syntax](#tab/classic-syntax) - -[!code-cs[Setting flags](SendingMessages/Program.cs#L255)] - -# [Fluent Syntax](#tab/fluent-syntax) - -[!code-cs[Setting flags](SendingMessages/Program.cs#L257)] - -*** diff --git a/Documentation/guides/basic-concepts/sharding.md b/Documentation/guides/basic-concepts/sharding.md deleted file mode 100644 index 7491b0102..000000000 --- a/Documentation/guides/basic-concepts/sharding.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -uid: sharding -omitAppTitle: true -title: Scale Your C# Discord Bot with Sharding in NetCord -description: Implement sharding for your C# Discord bot with NetCord to improve scalability and performance by distributing tasks across multiple gateway connections. ---- - -# Sharding - -Sharding allows your bot to split its responsibilities across multiple gateway connections. In NetCord, this is managed by the @NetCord.Gateway.ShardedGatewayClient, which acts as a controller for multiple instances of @NetCord.Gateway.GatewayClient. Each shard, represented by a @NetCord.Gateway.GatewayClient, handles a specific subset of guilds. - -## When to Shard - -Sharding becomes necessary when your bot exceeds 2,500 guilds. However, it's recommended to implement sharding earlier, typically when targeting 1,000+ guilds, to ensure smoother scaling and performance. - -## How to Shard - -### [.NET Generic Host](#tab/generic-host) - -When using the .NET Generic Host, you can add the @NetCord.Gateway.ShardedGatewayClient by calling @NetCord.Hosting.Gateway.ShardedGatewayClientServiceCollectionExtensions.AddDiscordShardedGateway*. -[!code-cs[Program.cs](ShardingHosting/Program.cs)] - -### [Bare Bones](#tab/bare-bones) - -For a bare-bones setup, you need to manually create an instance of @NetCord.Gateway.ShardedGatewayClient. Its API is very similar to @NetCord.Gateway.GatewayClient. Here's an example: -[!code-cs[Program.cs](Sharding/Program.cs)] - -*** - -## How to Register Events - -### [.NET Generic Host](#tab/generic-host) - -To register event handlers with sharding in the .NET Generic Host, use @NetCord.Hosting.Gateway.GatewayHandlerServiceCollectionExtensions.AddShardedGatewayHandlers* to add all event handlers in an assembly and then call @NetCord.Hosting.Gateway.GatewayHandlerServiceCollectionExtensions.AddShardedGatewayHandlers* to bind these handlers to the sharded client. - -[!code-cs[Program.cs](ShardingHosting/RegisteringHandlers.cs?highlight=10#L12-L25)] - -When creating event handlers, implement @NetCord.Hosting.Gateway.IShardedGatewayHandler. Note the additional parameter representing the @NetCord.Gateway.GatewayClient that received the event. -[!code-cs[Program.cs](ShardingHosting/MessageUpdateHandler.cs)] - -### [Bare Bones](#tab/bare-bones) - -For bare-bones setups, adding event handlers is straightforward. Each handler has an additional parameter for the @NetCord.Gateway.GatewayClient that received the event. -[!code-cs[Program.cs](Sharding/RegisteringHandlers.cs#L16-L19)] diff --git a/Documentation/guides/basic-concepts/voice.md b/Documentation/guides/basic-concepts/voice.md deleted file mode 100644 index 20a17452d..000000000 --- a/Documentation/guides/basic-concepts/voice.md +++ /dev/null @@ -1,16 +0,0 @@ -# Voice - -## Native Dependencies - -Follow the [installation guide](installing-native-dependencies.md) to install the required native dependencies. - -## Example Usage - -> [!NOTE] -> In the following examples streams and @NetCord.Gateway.Voice.VoiceClient instances are not disposed because they should be stored somewhere and disposed later. - -### Sending Voice -[!code-cs[VoiceModule.cs](Voice/VoiceModule.cs#L13-L110)] - -### Receiving Voice -[!code-cs[VoiceModule.cs](Voice/VoiceModule.cs#L112-L155)] diff --git a/Documentation/guides/events/FirstEvents/FirstEvents.csproj b/Documentation/guides/events/FirstEvents/FirstEvents.csproj deleted file mode 100644 index 75d3fd4b9..000000000 --- a/Documentation/guides/events/FirstEvents/FirstEvents.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - Exe - - - - - - - diff --git a/Documentation/guides/events/FirstEvents/Program.cs b/Documentation/guides/events/FirstEvents/Program.cs deleted file mode 100644 index 9e2378f23..000000000 --- a/Documentation/guides/events/FirstEvents/Program.cs +++ /dev/null @@ -1,22 +0,0 @@ -using NetCord; -using NetCord.Gateway; - -GatewayClient client = new(new BotToken("Token from Discord Developer Portal"), new GatewayClientConfiguration() -{ - Intents = GatewayIntents.GuildMessages - | GatewayIntents.DirectMessages - | GatewayIntents.MessageContent - | GatewayIntents.DirectMessageReactions - | GatewayIntents.GuildMessageReactions, -}); - -client.MessageCreate += message => -{ - Console.WriteLine(message.Content); - return default; -}; - -client.MessageReactionAdd += async args => -{ - await client.Rest.SendMessageAsync(args.ChannelId, $"<@{args.UserId}> reacted with {args.Emoji.Name}!"); -}; diff --git a/Documentation/guides/events/FirstEventsHosting/FirstEventsHosting.csproj b/Documentation/guides/events/FirstEventsHosting/FirstEventsHosting.csproj deleted file mode 100644 index e3fb763cf..000000000 --- a/Documentation/guides/events/FirstEventsHosting/FirstEventsHosting.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - - - - - - - - - - - - diff --git a/Documentation/guides/events/FirstEventsHosting/MessageCreateHandler.cs b/Documentation/guides/events/FirstEventsHosting/MessageCreateHandler.cs deleted file mode 100644 index 5ae956b04..000000000 --- a/Documentation/guides/events/FirstEventsHosting/MessageCreateHandler.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Microsoft.Extensions.Logging; - -using NetCord.Gateway; -using NetCord.Hosting.Gateway; - -namespace MyBot; - -public class MessageCreateHandler(ILogger logger) : IMessageCreateGatewayHandler -{ - public ValueTask HandleAsync(Message message) - { - logger.LogInformation("{}", message.Content); - return default; - } -} diff --git a/Documentation/guides/events/FirstEventsHosting/MessageReactionAddHandler.cs b/Documentation/guides/events/FirstEventsHosting/MessageReactionAddHandler.cs deleted file mode 100644 index 7e272c09c..000000000 --- a/Documentation/guides/events/FirstEventsHosting/MessageReactionAddHandler.cs +++ /dev/null @@ -1,13 +0,0 @@ -using NetCord.Gateway; -using NetCord.Hosting.Gateway; -using NetCord.Rest; - -namespace MyBot; - -public class MessageReactionAddHandler(RestClient client) : IMessageReactionAddGatewayHandler -{ - public async ValueTask HandleAsync(MessageReactionAddEventArgs args) - { - await client.SendMessageAsync(args.ChannelId, $"<@{args.UserId}> reacted with {args.Emoji.Name}!"); - } -} diff --git a/Documentation/guides/events/FirstEventsHosting/Program.cs b/Documentation/guides/events/FirstEventsHosting/Program.cs deleted file mode 100644 index 27a049b50..000000000 --- a/Documentation/guides/events/FirstEventsHosting/Program.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.Extensions.Hosting; - -using NetCord.Gateway; -using NetCord.Hosting.Gateway; - -var builder = Host.CreateApplicationBuilder(args); - -builder.Services - .AddDiscordGateway(options => - { - options.Intents = GatewayIntents.GuildMessages - | GatewayIntents.DirectMessages - | GatewayIntents.MessageContent - | GatewayIntents.DirectMessageReactions - | GatewayIntents.GuildMessageReactions; - }) - .AddGatewayHandlers(typeof(Program).Assembly); - -var host = builder.Build(); - -await host.RunAsync(); diff --git a/Documentation/guides/events/Intents/Intents.csproj b/Documentation/guides/events/Intents/Intents.csproj deleted file mode 100644 index 75d3fd4b9..000000000 --- a/Documentation/guides/events/Intents/Intents.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - Exe - - - - - - - diff --git a/Documentation/guides/events/Intents/Program.cs b/Documentation/guides/events/Intents/Program.cs deleted file mode 100644 index 812005b20..000000000 --- a/Documentation/guides/events/Intents/Program.cs +++ /dev/null @@ -1,7 +0,0 @@ -using NetCord; -using NetCord.Gateway; - -GatewayClient client = new(new BotToken("Token from Discord Developer Portal"), new GatewayClientConfiguration() -{ - Intents = GatewayIntents.GuildMessages | GatewayIntents.DirectMessages | GatewayIntents.MessageContent, -}); diff --git a/Documentation/guides/events/IntentsHosting/IntentsHosting.csproj b/Documentation/guides/events/IntentsHosting/IntentsHosting.csproj deleted file mode 100644 index e3fb763cf..000000000 --- a/Documentation/guides/events/IntentsHosting/IntentsHosting.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - - - - - - - - - - - - diff --git a/Documentation/guides/events/IntentsHosting/Program.cs b/Documentation/guides/events/IntentsHosting/Program.cs deleted file mode 100644 index a918e9371..000000000 --- a/Documentation/guides/events/IntentsHosting/Program.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.Extensions.Hosting; - -using NetCord.Gateway; -using NetCord.Hosting.Gateway; - -var builder = Host.CreateApplicationBuilder(args); - -builder.Services - .AddDiscordGateway(options => - { - options.Intents = GatewayIntents.GuildMessages | GatewayIntents.DirectMessages | GatewayIntents.MessageContent; - }); diff --git a/Documentation/guides/events/first-events.md b/Documentation/guides/events/first-events.md deleted file mode 100644 index df9b25a0a..000000000 --- a/Documentation/guides/events/first-events.md +++ /dev/null @@ -1,43 +0,0 @@ -# First Events - -## [.NET Generic Host](#tab/generic-host) - -The preferred way to receive events with the .NET Generic Host is by implementing appropriate @"NetCord.Hosting.Gateway.IGatewayHandler"s. An example of such an interface is @NetCord.Hosting.Gateway.IMessageCreateGatewayHandler. - -Use @NetCord.Hosting.Gateway.GatewayHandlerServiceCollectionExtensions.AddGatewayHandlers(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Reflection.Assembly) to add all event handlers in an assembly. -[!code-cs[Program.cs](FirstEventsHosting/Program.cs?highlight=17)] - -### MessageCreate Event -Now it's time to implement your MessageCreate event handler! -[!code-cs[Program.cs](FirstEventsHosting/MessageCreateHandler.cs)] - -When you run this code, when someone sends a message, the message will be printed on a console! - -### MessageReactionAdd Event -We will also implement a MessageReactionAdd event handler! -[!code-cs[Program.cs](FirstEventsHosting/MessageReactionAddHandler.cs)] - -When you run this code, when someone reacts to a message, the bot will notify everyone about it! - -### Other Events -Other events work similar to these. You can play with them if you want! - -> [!NOTE] -> When using @NetCord.Gateway.ShardedGatewayClient, you need to implement @NetCord.Hosting.Gateway.IShardedGatewayHandler instead. An example of such an interface is @NetCord.Hosting.Gateway.IMessageCreateShardedGatewayHandler. You also need to use @NetCord.Hosting.Gateway.GatewayHandlerServiceCollectionExtensions.AddShardedGatewayHandlers* to add event handlers. See @sharding?text=Sharding for more information. - -## [Bare Bones](#tab/bare-bones) - -### MessageCreate Event -To listen to the event, add the following lines before `client.StartAsync()`! -[!code-cs[Program.cs](FirstEvents/Program.cs#L13-L17)] - -When you run this code, when someone sends a message, the message will be printed on a console! - -### MessageReactionAdd Event -To listen to the event, add the following lines to your code. -[!code-cs[Program.cs](FirstEvents/Program.cs#L19-L22)] - -When you run this code, when someone reacts to a message, the bot will notify everyone about it! - -### Other Events -Other events work similar to these. You can play with them if you want! diff --git a/Documentation/guides/getting-started/Coding/Coding.csproj b/Documentation/guides/getting-started/Coding/Coding.csproj deleted file mode 100644 index 75d3fd4b9..000000000 --- a/Documentation/guides/getting-started/Coding/Coding.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - Exe - - - - - - - diff --git a/Documentation/guides/getting-started/Coding/Program.cs b/Documentation/guides/getting-started/Coding/Program.cs deleted file mode 100644 index c647a3601..000000000 --- a/Documentation/guides/getting-started/Coding/Program.cs +++ /dev/null @@ -1,11 +0,0 @@ -using NetCord; -using NetCord.Gateway; -using NetCord.Logging; - -GatewayClient client = new(new BotToken("Token from Discord Developer Portal"), new GatewayClientConfiguration -{ - Logger = new ConsoleLogger(), -}); - -await client.StartAsync(); -await Task.Delay(-1); diff --git a/Documentation/guides/getting-started/CodingHosting/CodingHosting.csproj b/Documentation/guides/getting-started/CodingHosting/CodingHosting.csproj deleted file mode 100644 index e3fb763cf..000000000 --- a/Documentation/guides/getting-started/CodingHosting/CodingHosting.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - - - - - - - - - - - - diff --git a/Documentation/guides/getting-started/CodingHosting/Program.cs b/Documentation/guides/getting-started/CodingHosting/Program.cs deleted file mode 100644 index d67b00b7a..000000000 --- a/Documentation/guides/getting-started/CodingHosting/Program.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.Extensions.Hosting; - -using NetCord.Hosting.Gateway; - -var builder = Host.CreateApplicationBuilder(args); - -builder.Services - .AddDiscordGateway(); - -var host = builder.Build(); - -await host.RunAsync(); diff --git a/Documentation/guides/getting-started/CodingHosting/appsettings.json b/Documentation/guides/getting-started/CodingHosting/appsettings.json deleted file mode 100644 index c6ef8532a..000000000 --- a/Documentation/guides/getting-started/CodingHosting/appsettings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "Discord": { - "Token": "Token from Discord Developer Portal" - } -} diff --git a/Documentation/guides/getting-started/making-a-bot.md b/Documentation/guides/getting-started/making-a-bot.md deleted file mode 100644 index 5e3cc46c0..000000000 --- a/Documentation/guides/getting-started/making-a-bot.md +++ /dev/null @@ -1,95 +0,0 @@ ---- -omitAppTitle: true -title: Building Your First C# Discord Bot with .NET and NetCord -description: Build your first C# Discord bot with .NET and NetCord! This guide walks you through setting up a bot, writing C# code, and connecting to the Discord API. ---- - -# Building Your First C# Discord Bot - -Looking to build your first C# Discord bot? This step-by-step guide will show you how to create a bot on Discord and connect it to the Discord API using C# and NetCord, a powerful .NET library designed for building efficient and scalable Discord bots. - -## Step 1: Setting Up Your Discord Bot on the Discord Developer Portal - -Before diving into the code, you need to set up your bot on the Discord Developer Portal. This is the first essential step to making your bot available on Discord. - -### Creating a Discord Bot Application - -1. Head over to the [Discord Developer Portal](https://discord.com/developers/applications). Click **New Application** in the **Applications** section. - ![Click 'New Application' in the 'Applications' section](../../images/making-a-bot_CreateApplication_1.webp){width=600px} - -2. Enter a name for your bot, check the box, and click **Create**. - ![Enter a name for your bot, check the box, and click 'Create'](../../images/making-a-bot_CreateApplication_2.webp){width=350px} - -### Adding Your Bot to a Discord Server - -Once your bot application is created, you need to invite it to a server to interact with users: - -1. In the **OAuth2** section, select the **bot** scope to generate an invite link. - ![Generate a bot invite link in 'OAuth2 > URL Generator' by selecting 'bot' scope](../../images/making-a-bot_AddBotToServer_1.webp){width=850px} - -2. Use the generated invite link, paste it into your browser, select a server, and click **Authorise**. - ![Paste the invite link into your browser, select a server, and click 'Authorise'](../../images/making-a-bot_AddBotToServer_2.webp){width=400px} - -### Retrieving Your Discord Bot Token - -Before running the code, you'll need to retrieve your bot's token, which will allow your bot to communicate with Discord's API. - -> [!IMPORTANT] -> Never share your bot token with anyone! It grants full control over your bot. - -1. Go to the **Bot** section in the application settings and click **Reset Token**. - ![Go to 'Bot' section and click 'Reset Token'](../../images/making-a-bot_Token_1.webp){width=600px} - -2. Copy the token and save it. You'll need it later to connect your bot to Discord. - ![Click 'Copy' to copy the bot token to the clipboard](../../images/making-a-bot_Token_2.webp){width=350px} - -## Step 2: Coding Your C# Discord Bot - -Now that your bot is set up on Discord, it's time to write the C# code to bring your bot to life. In this section, you can select between two approaches for building your C# bot: using the **.NET Generic Host** or a **Bare Bones** setup. - -### Choosing Between the .NET Generic Host and Bare Bones Approach - -- **.NET Generic Host:** This approach allows you to set up your C# bot with ease, leveraging the power of dependency injection. It's straightforward and integrates well with the rest of the .NET ecosystem. You can read more about it [here](https://learn.microsoft.com/dotnet/core/extensions/generic-host). -- **Bare Bones:** For developers who prefer direct control, this approach lets you handle everything manually. It gives you more flexibility but requires a bit more setup. - -Pick one based on your preference and project requirements. - -### Writing the C# Code - -#### [.NET Generic Host](#tab/generic-host) - -> [!NOTE] -> The .NET Generic Host approach requires the following packages: -> - [Microsoft.Extensions.Hosting](https://www.nuget.org/packages/Microsoft.Extensions.Hosting) -> - [NetCord.Hosting](https://www.nuget.org/packages/NetCord.Hosting) - -To set up the bot with the .NET Generic Host, simply use @NetCord.Hosting.Gateway.GatewayClientServiceCollectionExtensions.AddDiscordGateway*. Here's an example showing how to add the bot to the host. -[!code-cs[Program.cs](CodingHosting/Program.cs)] - -For better configuration management, store the token in an `appsettings.json` file like this: -[!code-json[appsettings.json](CodingHosting/appsettings.json)] - -#### [Bare Bones](#tab/bare-bones) - -To create the @NetCord.Gateway.GatewayClient manually, add the following lines to your `Program.cs` file. -[!code-cs[Program.cs](Coding/Program.cs#L1-L8)] - -We have also added a console logger to log messages to the console. This is useful for debugging and monitoring your bot's activity. - -Finally, start your bot with the following lines. -[!code-cs[Program.cs](Coding/Program.cs#L10-L11)] - -#### The Final Product -[!code-cs[Program.cs](Coding/Program.cs)] - -*** - -Now, when you run the code, your C# bot should be online! -![Bot being online](../../images/making-a-bot_BotOnline.webp) - -## Extending Your C# Discord Bot - -Now, as you have your bot up and running, you can start adding more features to it. Here are some common functionalities you might want to implement: - -- **@"application-commands?text=Application Commands":** Allow users to interact with your bot easily by creating slash commands, user commands, and message commands. -- **@"events?text=Events Handling":** Listen for and respond to various events, such as message creation or user joining a server. diff --git a/Documentation/guides/services/CustomModuleBasesAndContexts/CustomContexts/CustomCommandContext.cs b/Documentation/guides/services/CustomModuleBasesAndContexts/CustomContexts/CustomCommandContext.cs deleted file mode 100644 index 255fb1bf1..000000000 --- a/Documentation/guides/services/CustomModuleBasesAndContexts/CustomContexts/CustomCommandContext.cs +++ /dev/null @@ -1,10 +0,0 @@ -using NetCord; -using NetCord.Gateway; -using NetCord.Services.Commands; - -namespace MyBot; - -public class CustomCommandContext(Message message, GatewayClient client) : CommandContext(message, client) -{ - public GuildUser BotGuildUser => Guild!.Users[Client.Id]; -} diff --git a/Documentation/guides/services/CustomModuleBasesAndContexts/CustomContexts/CustomContexts.csproj b/Documentation/guides/services/CustomModuleBasesAndContexts/CustomContexts/CustomContexts.csproj deleted file mode 100644 index f4393da38..000000000 --- a/Documentation/guides/services/CustomModuleBasesAndContexts/CustomContexts/CustomContexts.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/Documentation/guides/services/CustomModuleBasesAndContexts/CustomContexts/ExampleModule.cs b/Documentation/guides/services/CustomModuleBasesAndContexts/CustomContexts/ExampleModule.cs deleted file mode 100644 index db85038e3..000000000 --- a/Documentation/guides/services/CustomModuleBasesAndContexts/CustomContexts/ExampleModule.cs +++ /dev/null @@ -1,15 +0,0 @@ -using NetCord.Services; -using NetCord.Services.Commands; - -namespace MyBot; - -public class ExampleModule : CommandModule -{ - [RequireContext(RequiredContext.Guild)] - [Command("botname")] - public string BotName() - { - var user = Context.BotGuildUser; - return user.Nickname ?? user.Username; - } -} diff --git a/Documentation/guides/services/CustomModuleBasesAndContexts/CustomModuleBases/CustomCommandModule.cs b/Documentation/guides/services/CustomModuleBasesAndContexts/CustomModuleBases/CustomCommandModule.cs deleted file mode 100644 index b32bb7e2c..000000000 --- a/Documentation/guides/services/CustomModuleBasesAndContexts/CustomModuleBases/CustomCommandModule.cs +++ /dev/null @@ -1,14 +0,0 @@ -using NetCord; -using NetCord.Services.Commands; - -namespace MyBot; - -public abstract class CustomCommandModule : CommandModule -{ - public Color GetUserColor(GuildUser user) - { - return (user.GetRoles(Context.Guild!) - .OrderByDescending(r => r.Position) - .FirstOrDefault(r => r.Color != default)?.Color).GetValueOrDefault(); - } -} diff --git a/Documentation/guides/services/CustomModuleBasesAndContexts/CustomModuleBases/CustomModuleBases.csproj b/Documentation/guides/services/CustomModuleBasesAndContexts/CustomModuleBases/CustomModuleBases.csproj deleted file mode 100644 index f4393da38..000000000 --- a/Documentation/guides/services/CustomModuleBasesAndContexts/CustomModuleBases/CustomModuleBases.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/Documentation/guides/services/CustomModuleBasesAndContexts/CustomModuleBases/ExampleModule.cs b/Documentation/guides/services/CustomModuleBasesAndContexts/CustomModuleBases/ExampleModule.cs deleted file mode 100644 index b6beab683..000000000 --- a/Documentation/guides/services/CustomModuleBasesAndContexts/CustomModuleBases/ExampleModule.cs +++ /dev/null @@ -1,17 +0,0 @@ -using NetCord; -using NetCord.Services; -using NetCord.Services.Commands; - -namespace MyBot; - -public class ExampleModule : CustomCommandModule -{ - [RequireContext(RequiredContext.Guild)] - [Command("color")] - public string Color(GuildUser? user = null) - { - user ??= (GuildUser)Context.User; - var color = GetUserColor(user); - return $"#{color.RawValue:X6}"; - } -} diff --git a/Documentation/guides/services/DependencyInjection/DataAutocompleteProvider.cs b/Documentation/guides/services/DependencyInjection/DataAutocompleteProvider.cs deleted file mode 100644 index d7c966a48..000000000 --- a/Documentation/guides/services/DependencyInjection/DataAutocompleteProvider.cs +++ /dev/null @@ -1,22 +0,0 @@ -using NetCord; -using NetCord.Rest; -using NetCord.Services.ApplicationCommands; - -namespace MyBot; - -public class DataAutocompleteProvider(ISomeService someService) : IAutocompleteProvider -{ - public ValueTask?> GetChoicesAsync( - ApplicationCommandInteractionDataOption option, - AutocompleteInteractionContext context) - { - var input = option.Value!; - var data = someService.GetSomeData(); - - var result = data.Where(d => d.Contains(input)) - .Take(25) - .Select(d => new ApplicationCommandOptionChoiceProperties(d, d)); - - return new(result); - } -} diff --git a/Documentation/guides/services/DependencyInjection/DataModule.cs b/Documentation/guides/services/DependencyInjection/DataModule.cs deleted file mode 100644 index 77a27674d..000000000 --- a/Documentation/guides/services/DependencyInjection/DataModule.cs +++ /dev/null @@ -1,9 +0,0 @@ -using NetCord.Services.Commands; - -namespace MyBot; - -public class DataModule(ISomeService someService) : CommandModule -{ - [Command("data")] - public string Data(int count) => string.Join(' ', someService.GetSomeData().Take(count)); -} diff --git a/Documentation/guides/services/DependencyInjection/DependencyInjection.csproj b/Documentation/guides/services/DependencyInjection/DependencyInjection.csproj deleted file mode 100644 index 8f7975131..000000000 --- a/Documentation/guides/services/DependencyInjection/DependencyInjection.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - - - - - - - - - - - - diff --git a/Documentation/guides/services/DependencyInjection/ISomeService.cs b/Documentation/guides/services/DependencyInjection/ISomeService.cs deleted file mode 100644 index c4f158814..000000000 --- a/Documentation/guides/services/DependencyInjection/ISomeService.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace MyBot; - -public interface ISomeService -{ - public IReadOnlyList GetSomeData(); -} - -public class SomeService : ISomeService -{ - public IReadOnlyList GetSomeData() => ["hello", "world"]; -} diff --git a/Documentation/guides/services/DependencyInjection/Program.cs b/Documentation/guides/services/DependencyInjection/Program.cs deleted file mode 100644 index 2a33d7522..000000000 --- a/Documentation/guides/services/DependencyInjection/Program.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -using MyBot; - -using NetCord; -using NetCord.Gateway; -using NetCord.Hosting.Gateway; -using NetCord.Hosting.Services; -using NetCord.Hosting.Services.ApplicationCommands; -using NetCord.Hosting.Services.Commands; -using NetCord.Services.ApplicationCommands; -using NetCord.Services.Commands; - -var builder = Host.CreateApplicationBuilder(args); - -builder.Services - .AddSingleton() - .AddDiscordGateway(o => o.Intents = GatewayIntents.GuildMessages | GatewayIntents.DirectMessages | GatewayIntents.MessageContent) - .AddCommands() - .AddApplicationCommands(); - -var host = builder.Build(); - -host.AddModules(typeof(Program).Assembly); - -host.AddSlashCommand( - name: "data", - description: "Shows the data!", - (ISomeService someService, ApplicationCommandContext context, int count) => string.Join(' ', - someService.GetSomeData() - .Take(count))); - -await host.RunAsync(); diff --git a/Documentation/guides/services/Preconditions/ParameterPreconditions/HelloModule.cs b/Documentation/guides/services/Preconditions/ParameterPreconditions/HelloModule.cs deleted file mode 100644 index 5c1bd5fd5..000000000 --- a/Documentation/guides/services/Preconditions/ParameterPreconditions/HelloModule.cs +++ /dev/null @@ -1,9 +0,0 @@ -using NetCord.Services.ApplicationCommands; - -namespace MyBot; - -public class HelloModule : ApplicationCommandModule -{ - [SlashCommand("hello", "Say hello!")] - public static string Hello([MustContain("hello")] string text) => text; -} diff --git a/Documentation/guides/services/Preconditions/ParameterPreconditions/MustContainAttribute.cs b/Documentation/guides/services/Preconditions/ParameterPreconditions/MustContainAttribute.cs deleted file mode 100644 index 2554463fa..000000000 --- a/Documentation/guides/services/Preconditions/ParameterPreconditions/MustContainAttribute.cs +++ /dev/null @@ -1,18 +0,0 @@ -using NetCord.Services; - -namespace MyBot; - -// We use generics to make our attribute usable for all types of commands and interactions at the same time -public class MustContainAttribute(string required) : ParameterPreconditionAttribute -{ - public override ValueTask EnsureCanExecuteAsync(object? value, TContext context, IServiceProvider? serviceProvider) - { - var text = (string)value!; - - // Return a fail result when the parameter value does not contain the required text - if (!text.Contains(required, StringComparison.InvariantCultureIgnoreCase)) - return new(PreconditionResult.Fail($"The parameter must contain '{required}'.")); - - return new(PreconditionResult.Success); - } -} diff --git a/Documentation/guides/services/Preconditions/ParameterPreconditions/ParameterPreconditions.csproj b/Documentation/guides/services/Preconditions/ParameterPreconditions/ParameterPreconditions.csproj deleted file mode 100644 index 22013d152..000000000 --- a/Documentation/guides/services/Preconditions/ParameterPreconditions/ParameterPreconditions.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - - - - - - - - - - - - diff --git a/Documentation/guides/services/Preconditions/ParameterPreconditions/Program.cs b/Documentation/guides/services/Preconditions/ParameterPreconditions/Program.cs deleted file mode 100644 index 1a01cac5a..000000000 --- a/Documentation/guides/services/Preconditions/ParameterPreconditions/Program.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Microsoft.Extensions.Hosting; - -using MyBot; - -using NetCord; -using NetCord.Hosting.Gateway; -using NetCord.Hosting.Services; -using NetCord.Hosting.Services.ApplicationCommands; -using NetCord.Hosting.Services.Commands; -using NetCord.Services.ApplicationCommands; -using NetCord.Services.Commands; - -var builder = Host.CreateApplicationBuilder(args); - -builder.Services - .AddDiscordGateway() - .AddApplicationCommands() - .AddCommands(); - -var host = builder.Build(); - -host.AddCommand( - aliases: ["bye"], - ([MustContain("bye")] string text) => text); - -host.AddModules(typeof(Program).Assembly); - -await host.RunAsync(); diff --git a/Documentation/guides/services/Preconditions/Preconditions/AvatarModule.cs b/Documentation/guides/services/Preconditions/Preconditions/AvatarModule.cs deleted file mode 100644 index 3bcc7555b..000000000 --- a/Documentation/guides/services/Preconditions/Preconditions/AvatarModule.cs +++ /dev/null @@ -1,10 +0,0 @@ -using NetCord.Services.Commands; - -namespace MyBot; - -public class AvatarModule : CommandModule -{ - [RequireAnimatedAvatar] - [Command("avatar")] - public string Avatar() => Context.User.GetAvatarUrl()!.ToString(); -} diff --git a/Documentation/guides/services/Preconditions/Preconditions/ButtonModule.cs b/Documentation/guides/services/Preconditions/Preconditions/ButtonModule.cs deleted file mode 100644 index 5727199d7..000000000 --- a/Documentation/guides/services/Preconditions/Preconditions/ButtonModule.cs +++ /dev/null @@ -1,9 +0,0 @@ -using NetCord.Services.ComponentInteractions; - -namespace MyBot; - -[RequireAnimatedAvatar] -public class ButtonModule : ComponentInteractionModule -{ - // All interactions here will require animated avatars -} diff --git a/Documentation/guides/services/Preconditions/Preconditions/Preconditions.csproj b/Documentation/guides/services/Preconditions/Preconditions/Preconditions.csproj deleted file mode 100644 index 22013d152..000000000 --- a/Documentation/guides/services/Preconditions/Preconditions/Preconditions.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - - - - - - - - - - - - diff --git a/Documentation/guides/services/Preconditions/Preconditions/Program.cs b/Documentation/guides/services/Preconditions/Preconditions/Program.cs deleted file mode 100644 index f12bbd13f..000000000 --- a/Documentation/guides/services/Preconditions/Preconditions/Program.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.Extensions.Hosting; - -using MyBot; - -using NetCord; -using NetCord.Hosting.Gateway; -using NetCord.Hosting.Services; -using NetCord.Hosting.Services.ApplicationCommands; -using NetCord.Hosting.Services.Commands; -using NetCord.Hosting.Services.ComponentInteractions; -using NetCord.Services.ApplicationCommands; -using NetCord.Services.Commands; -using NetCord.Services.ComponentInteractions; - -var builder = Host.CreateApplicationBuilder(args); - -builder.Services - .AddDiscordGateway() - .AddApplicationCommands() - .AddComponentInteractions() - .AddCommands(); - -var host = builder.Build(); - -host.AddSlashCommand( - name: "hi", - description: "Hi!", - [RequireAnimatedAvatar] () => "Hi! You can use this command because your avatar is animated!"); - -host.AddModules(typeof(Program).Assembly); - -await host.RunAsync(); diff --git a/Documentation/guides/services/Preconditions/Preconditions/RequireAnimatedAvatarAttribute.cs b/Documentation/guides/services/Preconditions/Preconditions/RequireAnimatedAvatarAttribute.cs deleted file mode 100644 index 842019ba9..000000000 --- a/Documentation/guides/services/Preconditions/Preconditions/RequireAnimatedAvatarAttribute.cs +++ /dev/null @@ -1,16 +0,0 @@ -using NetCord.Services; - -namespace MyBot; - -// We use generics to make our attribute usable for all types of commands and interactions at the same time -public class RequireAnimatedAvatarAttribute : PreconditionAttribute where TContext : IUserContext -{ - public override ValueTask EnsureCanExecuteAsync(TContext context, IServiceProvider? serviceProvider) - { - // Return a fail result when the user has no avatar or it's not animated - if (context.User.AvatarHash is not string hash || !hash.StartsWith("a_")) - return new(PreconditionResult.Fail("You need an animated avatar to use this.")); - - return new(PreconditionResult.Success); - } -} diff --git a/Documentation/guides/services/application-commands/Introduction/ExampleModule.cs b/Documentation/guides/services/application-commands/Introduction/ExampleModule.cs deleted file mode 100644 index afad139a1..000000000 --- a/Documentation/guides/services/application-commands/Introduction/ExampleModule.cs +++ /dev/null @@ -1,17 +0,0 @@ -using NetCord; -using NetCord.Rest; -using NetCord.Services.ApplicationCommands; - -namespace MyBot; - -public class ExampleModule : ApplicationCommandModule -{ - [SlashCommand("pong", "Pong!")] - public static string Pong() => "Ping!"; - - [UserCommand("ID")] - public static string Id(User user) => user.Id.ToString(); - - [MessageCommand("Timestamp")] - public static string Timestamp(RestMessage message) => message.CreatedAt.ToString(); -} diff --git a/Documentation/guides/services/application-commands/Introduction/Introduction.csproj b/Documentation/guides/services/application-commands/Introduction/Introduction.csproj deleted file mode 100644 index 7379c7dd7..000000000 --- a/Documentation/guides/services/application-commands/Introduction/Introduction.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - Exe - - - - - - - - diff --git a/Documentation/guides/services/application-commands/Introduction/Program.cs b/Documentation/guides/services/application-commands/Introduction/Program.cs deleted file mode 100644 index 0502b049d..000000000 --- a/Documentation/guides/services/application-commands/Introduction/Program.cs +++ /dev/null @@ -1,53 +0,0 @@ -using NetCord; -using NetCord.Gateway; -using NetCord.Logging; -using NetCord.Rest; -using NetCord.Services; -using NetCord.Services.ApplicationCommands; - -GatewayClient client = new(new BotToken("Token from Discord Developer Portal"), new GatewayClientConfiguration -{ - Intents = default, - Logger = new ConsoleLogger(), -}); - -// Create the application command service -ApplicationCommandService applicationCommandService = new(); - -// Add commands using minimal APIs -applicationCommandService.AddSlashCommand(new SlashCommandBuilder("ping", "Ping!", () => "Pong!")); -applicationCommandService.AddUserCommand(new UserCommandBuilder("Username", (User user) => user.Username)); -applicationCommandService.AddMessageCommand(new MessageCommandBuilder("Length", (RestMessage message) => message.Content.Length.ToString())); - -// Add commands from modules -applicationCommandService.AddModules(typeof(Program).Assembly); - -// Add the handler to handle interactions -client.InteractionCreate += async interaction => -{ - // Check if the interaction is an application command interaction - if (interaction is not ApplicationCommandInteraction applicationCommandInteraction) - return; - - // Execute the command - var result = await applicationCommandService.ExecuteAsync(new ApplicationCommandContext(applicationCommandInteraction, client)); - - // Check if the execution failed - if (result is not IFailResult failResult) - return; - - // Return the error message to the user if the execution failed - try - { - await interaction.SendResponseAsync(InteractionCallback.Message(failResult.Message)); - } - catch - { - } -}; - -// Register the commands so that you can use them in the Discord client -await applicationCommandService.RegisterCommandsAsync(client.Rest, client.Id); - -await client.StartAsync(); -await Task.Delay(-1); diff --git a/Documentation/guides/services/application-commands/IntroductionHosting/IntroductionHosting.csproj b/Documentation/guides/services/application-commands/IntroductionHosting/IntroductionHosting.csproj deleted file mode 100644 index 3b76374f3..000000000 --- a/Documentation/guides/services/application-commands/IntroductionHosting/IntroductionHosting.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - - - - - - - - - - - - diff --git a/Documentation/guides/services/application-commands/IntroductionHosting/Program.cs b/Documentation/guides/services/application-commands/IntroductionHosting/Program.cs deleted file mode 100644 index 0d818414a..000000000 --- a/Documentation/guides/services/application-commands/IntroductionHosting/Program.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.Extensions.Hosting; - -using NetCord; -using NetCord.Hosting.Gateway; -using NetCord.Hosting.Services; -using NetCord.Hosting.Services.ApplicationCommands; -using NetCord.Rest; - -var builder = Host.CreateApplicationBuilder(args); - -builder.Services - .AddDiscordGateway() - .AddApplicationCommands(); - -var host = builder.Build(); - -// Add commands using minimal APIs -host.AddSlashCommand("ping", "Ping!", () => "Pong!"); -host.AddUserCommand("Username", (User user) => user.Username); -host.AddMessageCommand("Length", (RestMessage message) => message.Content.Length.ToString()); - -// Add commands from modules -host.AddModules(typeof(Program).Assembly); - -await host.RunAsync(); diff --git a/Documentation/guides/services/application-commands/Localizations/AnimalModule.cs b/Documentation/guides/services/application-commands/Localizations/AnimalModule.cs deleted file mode 100644 index 97b50c398..000000000 --- a/Documentation/guides/services/application-commands/Localizations/AnimalModule.cs +++ /dev/null @@ -1,22 +0,0 @@ -using NetCord.Services.ApplicationCommands; - -namespace MyBot; - -public class AnimalModule : ApplicationCommandModule -{ - [SlashCommand("animal", "Sends the animal you selected")] - public static string Animal( - [SlashCommandParameter(Description = "Animal to send")] Animal animal) - { - return animal.ToString(); - } -} - -public enum Animal -{ - Dog, - Cat, - Fish, - [SlashCommandChoice(Name = "Guinea Pig")] - GuineaPig, -} diff --git a/Documentation/guides/services/application-commands/Localizations/Localizations.csproj b/Documentation/guides/services/application-commands/Localizations/Localizations.csproj deleted file mode 100644 index 590515c2d..000000000 --- a/Documentation/guides/services/application-commands/Localizations/Localizations.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - Exe - - - - - - - - - - PreserveNewest - - - - diff --git a/Documentation/guides/services/application-commands/Localizations/Localizations/pl.json b/Documentation/guides/services/application-commands/Localizations/Localizations/pl.json deleted file mode 100644 index f8aa1052a..000000000 --- a/Documentation/guides/services/application-commands/Localizations/Localizations/pl.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "commands": { - "animal": { - "name": "zwierzę", - "description": "Wysyła zwierzę, które wybrałeś", - "parameters": { - "animal": { - "name": "zwierzę", - "description": "Zwierzę do wysłania" - } - } - }, - "permissions": { - "name": "uprawnienia", - "description": "Zarządza uprawnieniami", - "subcommands": { - "user": { - "name": "użytkownik", - "description": "Zarządza uprawnienia użytkownika", - "subcommands": { - "show": { - "name": "pokaż", - "description": "Pokazuje uprawnienia użytkownika", - "parameters": { - "user": { - "name": "użytkownik", - "description": "Użytkownik, którego uprawnienia chcesz zobaczyć" - } - } - } - } - }, - "channel": { - "name": "kanał", - "description": "Zarządza uprawnieniami kanału", - "subcommands": { - "show": { - "name": "pokaż", - "description": "Pokazuje uprawnienia kanału", - "parameters": { - "role": { - "name": "kanał", - "description": "Kanał, którego uprawnienia chcesz zobaczyć" - } - } - } - } - } - } - } - }, - "enums": { - "MyBot.Animal": { - "Dog": "Pies", - "Cat": "Kot", - "Fish": "Ryba", - "GuineaPig": "Świnka morska" - } - } -} diff --git a/Documentation/guides/services/application-commands/Localizations/PermissionsModule.cs b/Documentation/guides/services/application-commands/Localizations/PermissionsModule.cs deleted file mode 100644 index 98bd8e73b..000000000 --- a/Documentation/guides/services/application-commands/Localizations/PermissionsModule.cs +++ /dev/null @@ -1,30 +0,0 @@ -using NetCord; -using NetCord.Services.ApplicationCommands; - -namespace MyBot; - -[SlashCommand("permissions", "Manages permissions")] -public class PermissionsModule : ApplicationCommandModule -{ - [SubSlashCommand("user", "Manages user permissions")] - public class UserPermissionsModule : ApplicationCommandModule - { - [SubSlashCommand("show", "Shows user permissions")] - public static string Show( - [SlashCommandParameter(Description = "The user whose permissions you want to see")] GuildUser user) - { - return ((GuildInteractionUser)user).Permissions.ToString(); - } - } - - [SubSlashCommand("channel", "Manages channel permissions")] - public class ChannelPermissionsModule : ApplicationCommandModule - { - [SubSlashCommand("show", "Shows channel permissions")] - public static string Show( - [SlashCommandParameter(Description = "The channel whose permissions you want to see")] IGuildChannel channel) - { - return ((IInteractionChannel)channel).Permissions.ToString(); - } - } -} diff --git a/Documentation/guides/services/application-commands/Localizations/Program.cs b/Documentation/guides/services/application-commands/Localizations/Program.cs deleted file mode 100644 index 66267a881..000000000 --- a/Documentation/guides/services/application-commands/Localizations/Program.cs +++ /dev/null @@ -1,43 +0,0 @@ -using NetCord; -using NetCord.Gateway; -using NetCord.Logging; -using NetCord.Rest; -using NetCord.Services; -using NetCord.Services.ApplicationCommands; - -GatewayClient client = new(new BotToken("Token from Discord Developer Portal"), new GatewayClientConfiguration -{ - Intents = default, - Logger = new ConsoleLogger(), -}); - -ApplicationCommandService applicationCommandService = new(ApplicationCommandServiceConfiguration.Default with -{ - LocalizationsProvider = new JsonLocalizationsProvider(), -}); - -applicationCommandService.AddModules(typeof(Program).Assembly); - -client.InteractionCreate += async interaction => -{ - if (interaction is not ApplicationCommandInteraction applicationCommandInteraction) - return; - - var result = await applicationCommandService.ExecuteAsync(new ApplicationCommandContext(applicationCommandInteraction, client)); - - if (result is not IFailResult failResult) - return; - - try - { - await interaction.SendResponseAsync(InteractionCallback.Message(failResult.Message)); - } - catch - { - } -}; - -await applicationCommandService.RegisterCommandsAsync(client.Rest, client.Id); - -await client.StartAsync(); -await Task.Delay(-1); diff --git a/Documentation/guides/services/application-commands/LocalizationsHosting/LocalizationsHosting.csproj b/Documentation/guides/services/application-commands/LocalizationsHosting/LocalizationsHosting.csproj deleted file mode 100644 index 3b76374f3..000000000 --- a/Documentation/guides/services/application-commands/LocalizationsHosting/LocalizationsHosting.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - - - - - - - - - - - - diff --git a/Documentation/guides/services/application-commands/LocalizationsHosting/Program.cs b/Documentation/guides/services/application-commands/LocalizationsHosting/Program.cs deleted file mode 100644 index b6c839389..000000000 --- a/Documentation/guides/services/application-commands/LocalizationsHosting/Program.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.Extensions.Hosting; - -using NetCord.Hosting.Gateway; -using NetCord.Hosting.Services; -using NetCord.Hosting.Services.ApplicationCommands; -using NetCord.Services.ApplicationCommands; - -var builder = Host.CreateApplicationBuilder(args); - -builder.Services - .AddApplicationCommands(options => - { - options.LocalizationsProvider = new JsonLocalizationsProvider(); - }) - .AddDiscordGateway(); - -var host = builder.Build() - .AddModules(typeof(Program).Assembly); - -await host.RunAsync(); diff --git a/Documentation/guides/services/application-commands/MultipleServices/MultipleServices.csproj b/Documentation/guides/services/application-commands/MultipleServices/MultipleServices.csproj deleted file mode 100644 index 696a9094a..000000000 --- a/Documentation/guides/services/application-commands/MultipleServices/MultipleServices.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - Exe - - - - - - - - diff --git a/Documentation/guides/services/application-commands/MultipleServices/Program.cs b/Documentation/guides/services/application-commands/MultipleServices/Program.cs deleted file mode 100644 index bfcd95641..000000000 --- a/Documentation/guides/services/application-commands/MultipleServices/Program.cs +++ /dev/null @@ -1,49 +0,0 @@ -using NetCord; -using NetCord.Gateway; -using NetCord.Logging; -using NetCord.Rest; -using NetCord.Services; -using NetCord.Services.ApplicationCommands; - -GatewayClient client = new(new BotToken("Token from Discord Developer Portal"), new GatewayClientConfiguration -{ - Intents = default, - Logger = new ConsoleLogger(), -}); - -ApplicationCommandService slashCommandService = new(); -ApplicationCommandService messageCommandService = new(); - -ApplicationCommandServiceManager manager = new(); -manager.AddService(slashCommandService); -manager.AddService(messageCommandService); - -var assembly = typeof(Program).Assembly; -slashCommandService.AddModules(assembly); -messageCommandService.AddModules(assembly); - -client.InteractionCreate += async interaction => -{ - var result = await (interaction switch - { - SlashCommandInteraction slashCommandInteraction => slashCommandService.ExecuteAsync(new SlashCommandContext(slashCommandInteraction, client)), - MessageCommandInteraction messageCommandInteraction => messageCommandService.ExecuteAsync(new MessageCommandContext(messageCommandInteraction, client)), - _ => throw new("Invalid interaction."), - }); - - if (result is not IFailResult failResult) - return; - - try - { - await interaction.SendResponseAsync(InteractionCallback.Message(failResult.Message)); - } - catch - { - } -}; - -await manager.RegisterCommandsAsync(client.Rest, client.Id); - -await client.StartAsync(); -await Task.Delay(-1); diff --git a/Documentation/guides/services/application-commands/Parameters/Animal.cs b/Documentation/guides/services/application-commands/Parameters/Animal.cs deleted file mode 100644 index 0076a7765..000000000 --- a/Documentation/guides/services/application-commands/Parameters/Animal.cs +++ /dev/null @@ -1,12 +0,0 @@ -using NetCord.Services.ApplicationCommands; - -namespace MyBot; - -public enum Animal -{ - Dog, - Cat, - Fish, - [SlashCommandChoice(Name = "Guinea Pig")] - GuineaPig, -} diff --git a/Documentation/guides/services/application-commands/Parameters/ExampleModule.cs b/Documentation/guides/services/application-commands/Parameters/ExampleModule.cs deleted file mode 100644 index 9a00b7fde..000000000 --- a/Documentation/guides/services/application-commands/Parameters/ExampleModule.cs +++ /dev/null @@ -1,25 +0,0 @@ -using NetCord; -using NetCord.Services.ApplicationCommands; - -namespace MyBot; - -public class ExampleModule : ApplicationCommandModule -{ - [SlashCommand("username", "Returns user's username")] - public string Username(User? user = null) - { - user ??= Context.User; - return user.Username; - } - - [SlashCommand("power", "Raises a number to a power")] - public static string Power( - [SlashCommandParameter(Name = "base", Description = "The base")] double @base, - [SlashCommandParameter(Description = "The power")] double power = 2) - { - return $"Result: {Math.Pow(@base, power)}"; - } - - [SlashCommand("animal", "Sends animal you selected")] - public static string Animal(Animal animal) => animal.ToString(); -} diff --git a/Documentation/guides/services/application-commands/Parameters/Parameters.csproj b/Documentation/guides/services/application-commands/Parameters/Parameters.csproj deleted file mode 100644 index 696a9094a..000000000 --- a/Documentation/guides/services/application-commands/Parameters/Parameters.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - Exe - - - - - - - - diff --git a/Documentation/guides/services/application-commands/Parameters/Program.cs b/Documentation/guides/services/application-commands/Parameters/Program.cs deleted file mode 100644 index c23207606..000000000 --- a/Documentation/guides/services/application-commands/Parameters/Program.cs +++ /dev/null @@ -1,39 +0,0 @@ -using NetCord; -using NetCord.Gateway; -using NetCord.Logging; -using NetCord.Rest; -using NetCord.Services; -using NetCord.Services.ApplicationCommands; - -GatewayClient client = new(new BotToken("Token from Discord Developer Portal"), new GatewayClientConfiguration -{ - Intents = default, - Logger = new ConsoleLogger(), -}); - -ApplicationCommandService applicationCommandService = new(); -applicationCommandService.AddModules(typeof(Program).Assembly); - -client.InteractionCreate += async interaction => -{ - if (interaction is not ApplicationCommandInteraction applicationCommandInteraction) - return; - - var result = await applicationCommandService.ExecuteAsync(new ApplicationCommandContext(applicationCommandInteraction, client)); - - if (result is not IFailResult failResult) - return; - - try - { - await interaction.SendResponseAsync(InteractionCallback.Message(failResult.Message)); - } - catch - { - } -}; - -await applicationCommandService.RegisterCommandsAsync(client.Rest, client.Id); - -await client.StartAsync(); -await Task.Delay(-1); diff --git a/Documentation/guides/services/application-commands/Permissions/ExampleModule.cs b/Documentation/guides/services/application-commands/Permissions/ExampleModule.cs deleted file mode 100644 index 120150a77..000000000 --- a/Documentation/guides/services/application-commands/Permissions/ExampleModule.cs +++ /dev/null @@ -1,20 +0,0 @@ -using NetCord; -using NetCord.Rest; -using NetCord.Services.ApplicationCommands; - -namespace MyBot; - -public class ExampleModule : ApplicationCommandModule -{ - [SlashCommand("mention-everyone", "Mentions @everyone", - DefaultGuildPermissions = Permissions.MentionEveryone, - Contexts = [InteractionContextType.Guild])] - public static InteractionMessageProperties MentionEveryone() - { - return new() - { - AllowedMentions = AllowedMentionsProperties.All, - Content = "@everyone", - }; - } -} diff --git a/Documentation/guides/services/application-commands/Permissions/Permissions.csproj b/Documentation/guides/services/application-commands/Permissions/Permissions.csproj deleted file mode 100644 index 696a9094a..000000000 --- a/Documentation/guides/services/application-commands/Permissions/Permissions.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - Exe - - - - - - - - diff --git a/Documentation/guides/services/application-commands/Permissions/Program.cs b/Documentation/guides/services/application-commands/Permissions/Program.cs deleted file mode 100644 index c23207606..000000000 --- a/Documentation/guides/services/application-commands/Permissions/Program.cs +++ /dev/null @@ -1,39 +0,0 @@ -using NetCord; -using NetCord.Gateway; -using NetCord.Logging; -using NetCord.Rest; -using NetCord.Services; -using NetCord.Services.ApplicationCommands; - -GatewayClient client = new(new BotToken("Token from Discord Developer Portal"), new GatewayClientConfiguration -{ - Intents = default, - Logger = new ConsoleLogger(), -}); - -ApplicationCommandService applicationCommandService = new(); -applicationCommandService.AddModules(typeof(Program).Assembly); - -client.InteractionCreate += async interaction => -{ - if (interaction is not ApplicationCommandInteraction applicationCommandInteraction) - return; - - var result = await applicationCommandService.ExecuteAsync(new ApplicationCommandContext(applicationCommandInteraction, client)); - - if (result is not IFailResult failResult) - return; - - try - { - await interaction.SendResponseAsync(InteractionCallback.Message(failResult.Message)); - } - catch - { - } -}; - -await applicationCommandService.RegisterCommandsAsync(client.Rest, client.Id); - -await client.StartAsync(); -await Task.Delay(-1); diff --git a/Documentation/guides/services/application-commands/Subcommands/GuildCommandsModule.cs b/Documentation/guides/services/application-commands/Subcommands/GuildCommandsModule.cs deleted file mode 100644 index 513eb70dd..000000000 --- a/Documentation/guides/services/application-commands/Subcommands/GuildCommandsModule.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NetCord; -using NetCord.Services; -using NetCord.Services.ApplicationCommands; - -namespace MyBot; - -[SlashCommand("guild", "Guild command")] -public class GuildCommandsModule : ApplicationCommandModule -{ - [SubSlashCommand("channels", "Get guild channel count")] - public string Channels() => $"Channels: {Context.Guild!.Channels.Count}"; - - [SubSlashCommand("name", "Guild name")] - public class GuildNameModule : ApplicationCommandModule - { - [SubSlashCommand("get", "Get guild name")] - public string GetName() => $"Name: {Context.Guild!.Name}"; - - [RequireUserPermissions(Permissions.ManageGuild)] - [RequireBotPermissions(Permissions.ManageGuild)] - [SubSlashCommand("set", "Set guild name")] - public async Task SetNameAsync(string name) - { - var guild = Context.Guild!; - await guild.ModifyAsync(g => g.Name = name); - return $"Name: {guild.Name} -> {name}"; - } - } -} diff --git a/Documentation/guides/services/application-commands/Subcommands/Program.cs b/Documentation/guides/services/application-commands/Subcommands/Program.cs deleted file mode 100644 index 9b7dfcab4..000000000 --- a/Documentation/guides/services/application-commands/Subcommands/Program.cs +++ /dev/null @@ -1,39 +0,0 @@ -using NetCord; -using NetCord.Gateway; -using NetCord.Logging; -using NetCord.Rest; -using NetCord.Services; -using NetCord.Services.ApplicationCommands; - -GatewayClient client = new(new BotToken("Token from Discord Developer Portal"), new GatewayClientConfiguration -{ - Intents = GatewayIntents.Guilds, - Logger = new ConsoleLogger(), -}); - -ApplicationCommandService applicationCommandService = new(); -applicationCommandService.AddModules(typeof(Program).Assembly); - -client.InteractionCreate += async interaction => -{ - if (interaction is not ApplicationCommandInteraction applicationCommandInteraction) - return; - - var result = await applicationCommandService.ExecuteAsync(new ApplicationCommandContext(applicationCommandInteraction, client)); - - if (result is not IFailResult failResult) - return; - - try - { - await interaction.SendResponseAsync(InteractionCallback.Message(failResult.Message)); - } - catch - { - } -}; - -await applicationCommandService.RegisterCommandsAsync(client.Rest, client.Id); - -await client.StartAsync(); -await Task.Delay(-1); diff --git a/Documentation/guides/services/application-commands/Subcommands/Subcommands.csproj b/Documentation/guides/services/application-commands/Subcommands/Subcommands.csproj deleted file mode 100644 index 696a9094a..000000000 --- a/Documentation/guides/services/application-commands/Subcommands/Subcommands.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - Exe - - - - - - - - diff --git a/Documentation/guides/services/application-commands/introduction.md b/Documentation/guides/services/application-commands/introduction.md deleted file mode 100644 index 831154d6a..000000000 --- a/Documentation/guides/services/application-commands/introduction.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -uid: application-commands ---- - -# Introduction - -## [.NET Generic Host](#tab/generic-host) - -Adding application commands with the .NET Generic Host is very easy. Use @NetCord.Hosting.Services.ApplicationCommands.ApplicationCommandServiceServiceCollectionExtensions.AddApplicationCommands(Microsoft.Extensions.DependencyInjection.IServiceCollection) to add the application command service to your host builder. Then, use @NetCord.Hosting.Services.ApplicationCommands.ApplicationCommandServiceHostExtensions.AddSlashCommand*, @NetCord.Hosting.Services.ApplicationCommands.ApplicationCommandServiceHostExtensions.AddUserCommand* or @NetCord.Hosting.Services.ApplicationCommands.ApplicationCommandServiceHostExtensions.AddMessageCommand* to add an application command using the minimal APIs way and/or use @NetCord.Hosting.Services.ServicesHostExtensions.AddModules(Microsoft.Extensions.Hosting.IHost,System.Reflection.Assembly) to add application command modules from an assembly. -[!code-cs[Program.cs](IntroductionHosting/Program.cs?highlight=13,18-20,23)] - -## [Bare Bones](#tab/bare-bones) - -First, add the following lines to the using section. -[!code-cs[Program.cs](Introduction/Program.cs#L4-L6)] - -Now, it's time to create @NetCord.Services.ApplicationCommands.ApplicationCommandService`1 instance and add application commands to it. You can do it by using @NetCord.Services.ApplicationCommands.ApplicationCommandService`1.AddSlashCommand*, @NetCord.Services.ApplicationCommands.ApplicationCommandService`1.AddUserCommand* or @NetCord.Services.ApplicationCommands.ApplicationCommandService`1.AddMessageCommand* to add an application command using the minimal APIs way and/or by using @NetCord.Services.ApplicationCommands.ApplicationCommandService`1.AddModules(System.Reflection.Assembly) to add application command modules from an assembly. -[!code-cs[Program.cs](Introduction/Program.cs#L14-L23)] - -We can add a command handler now. If you used a context other than @NetCord.Services.ApplicationCommands.ApplicationCommandContext, you may need to change the interaction type of the handler to the appropriate one. -[!code-cs[Program.cs](Introduction/Program.cs#L25-L47)] - -Now, we should send the commands to Discord, to make them usable. Add the following line under the handler: -[!code-cs[Program.cs](Introduction/Program.cs#L49-L50)] - -### The Final Product - -#### Program.cs -[!code-cs[Program.cs](Introduction/Program.cs)] - -*** - -> [!NOTE] -> If you don't see the commands in Discord, try refreshing the Discord client using `Ctrl + R` on PC or `⌘ + R` on Mac. - -> [!IMPORTANT] -> Please note that names of slash commands must be lowercase. - -### Example Module - -Here you can see an example module showing how to use modules with application commands. -[!code-cs[ExampleModule.cs](Introduction/ExampleModule.cs)] diff --git a/Documentation/guides/services/application-commands/localizations.md b/Documentation/guides/services/application-commands/localizations.md deleted file mode 100644 index 7c9725a05..000000000 --- a/Documentation/guides/services/application-commands/localizations.md +++ /dev/null @@ -1,31 +0,0 @@ -# Localizations - -To localize application commands, you need to use @NetCord.Services.ApplicationCommands.ILocalizationsProvider. You specify it in the configuration. - -## Specifying the localizations provider - -The samples below show how to specify the @NetCord.Services.ApplicationCommands.JsonLocalizationsProvider. - -## [.NET Generic Host](#tab/generic-host) -[!code-cs[Program.cs](LocalizationsHosting/Program.cs?highlight=4#L10-L14)] - -## [Bare Bones](#tab/bare-bones) -[!code-cs[Program.cs](Localizations/Program.cs?highlight=3#L14-L17)] - -*** - -## Localizing commands with the @NetCord.Services.ApplicationCommands.JsonLocalizationsProvider - -The @NetCord.Services.ApplicationCommands.JsonLocalizationsProvider employs JSON files to localize commands. By default, these JSON files are expected to reside in the `Localizations` directory, with each file named after its respective locale in the format `{locale}.json`. For instance, a Polish localization file might be named `pl.json`. A list of supported locales can be found [here](https://discord.com/developers/docs/reference#locales). - -### Example - -The file below shows Polish localization of `permissions` and `animal` commands. - -[!code-json[pl.json](Localizations/Localizations/pl.json)] - -Here are the commands. - -[!code-cs[AnimalModule.cs](Localizations/AnimalModule.cs)] - -[!code-cs[PermissionsModule.cs](Localizations/PermissionsModule.cs)] diff --git a/Documentation/guides/services/application-commands/multiple-services.md b/Documentation/guides/services/application-commands/multiple-services.md deleted file mode 100644 index 9b85eae57..000000000 --- a/Documentation/guides/services/application-commands/multiple-services.md +++ /dev/null @@ -1,8 +0,0 @@ -# Multiple Services - -> [!NOTE] -> When using hosting, multiple instances of @NetCord.Services.ApplicationCommands.ApplicationCommandService`1 are handled automatically, so no additional configuration is needed. - -In some scenarios, you might want to use multiple instances of @NetCord.Services.ApplicationCommands.ApplicationCommandService`1. For instance, you may want to use different contexts for different application commands. In such cases, you can utilize the @NetCord.Services.ApplicationCommands.ApplicationCommandServiceManager, which allows you to register commands to Discord from different instances of @NetCord.Services.ApplicationCommands.ApplicationCommandService`1 simultaneously. - -[!code-cs[Program.cs](MultipleServices/Program.cs)] diff --git a/Documentation/guides/services/application-commands/parameters.md b/Documentation/guides/services/application-commands/parameters.md deleted file mode 100644 index 83e7effb9..000000000 --- a/Documentation/guides/services/application-commands/parameters.md +++ /dev/null @@ -1,47 +0,0 @@ -# Parameters - -## Slash Commands - -Slash commands support up to 25 parameters. - -### Optional parameters - -To mark parameters as optional, give them a default value, example: -[!code-cs[ExampleModule.cs](Parameters/ExampleModule.cs#L8-L13)] - -### Parameter name and description - -You can change parameter name and parameter description using @NetCord.Services.ApplicationCommands.SlashCommandParameterAttribute, example: -[!code-cs[ExampleModule.cs](Parameters/ExampleModule.cs#L15-L21)] - -### Min and Max Values - -You can specify min and max parameter values by setting @NetCord.Services.ApplicationCommands.SlashCommandParameterAttribute.MinValue and @NetCord.Services.ApplicationCommands.SlashCommandParameterAttribute.MaxValue properties in @NetCord.Services.ApplicationCommands.SlashCommandParameterAttribute. It's only possible for numeric types. - -### Min and Max Length - -You can specify min and max parameter length by setting @NetCord.Services.ApplicationCommands.SlashCommandParameterAttribute.MinLength and @NetCord.Services.ApplicationCommands.SlashCommandParameterAttribute.MaxLength properties in @NetCord.Services.ApplicationCommands.SlashCommandParameterAttribute. It's only possible for text types. - -### Choices and Autocomplete - -Choices are constants for a given parameter, autocomplete may depend on a text entered by a user. - -#### Choices - -Choices are automatically generated when you set `enum` as a parameter type, you can override choices' names using @NetCord.Services.ApplicationCommands.SlashCommandChoiceAttribute on enum fields, example: -[!code-cs[ExampleModule.cs](Parameters/ExampleModule.cs#L23-L24)] -[!code-cs[Animal.cs](Parameters/Animal.cs#l5-L12)] - -You can also define own choices in the Type Reader by overriding @NetCord.Services.ApplicationCommands.SlashCommandTypeReader`1.ChoicesProvider property or in @NetCord.Services.ApplicationCommands.SlashCommandParameterAttribute by setting @NetCord.Services.ApplicationCommands.SlashCommandParameterAttribute.ChoicesProviderType property. - -#### Autocomplete - -You can turn on autocomplete in Type Reader by overriding @NetCord.Services.ApplicationCommands.SlashCommandTypeReader`1.AutocompleteProviderType property or in @NetCord.Services.ApplicationCommands.SlashCommandParameterAttribute by setting @NetCord.Services.ApplicationCommands.SlashCommandParameterAttribute.AutocompleteProviderType property. You run it using @NetCord.Services.ApplicationCommands.ApplicationCommandService`2.ExecuteAutocompleteAsync(`1,System.IServiceProvider). - -## User Commands - -User commands only support a single parameter of type @NetCord.User. It's is not required, but allows you to access the target user of the user command easily. - -## Message Commands - -Message commands only support a single parameter of type @NetCord.Rest.RestMessage. It's is not required, but allows you to access the target message of the message command easily. diff --git a/Documentation/guides/services/application-commands/permissions.md b/Documentation/guides/services/application-commands/permissions.md deleted file mode 100644 index bcd16420c..000000000 --- a/Documentation/guides/services/application-commands/permissions.md +++ /dev/null @@ -1,4 +0,0 @@ -# Permissions - -Instead of using Precondition Attributes, you can specify command required permissions to Discord. The commands will not show up to users without the permissions then. You can also specify if commands can be used in DM. Example: -[!code-cs[ExampleModule.cs](Permissions/ExampleModule.cs#L9-L19)] diff --git a/Documentation/guides/services/application-commands/subcommands.md b/Documentation/guides/services/application-commands/subcommands.md deleted file mode 100644 index f7886cbfe..000000000 --- a/Documentation/guides/services/application-commands/subcommands.md +++ /dev/null @@ -1,7 +0,0 @@ -# Subcommands - -> [!NOTE] -> Subcommands are only supported by slash commands. - -## Example -[!code-cs[GuildCommandsModule.cs](Subcommands/GuildCommandsModule.cs)] diff --git a/Documentation/guides/services/component-interactions/Introduction/ButtonModule.cs b/Documentation/guides/services/component-interactions/Introduction/ButtonModule.cs deleted file mode 100644 index e5df821af..000000000 --- a/Documentation/guides/services/component-interactions/Introduction/ButtonModule.cs +++ /dev/null @@ -1,9 +0,0 @@ -using NetCord.Services.ComponentInteractions; - -namespace MyBot; - -public class ButtonModule : ComponentInteractionModule -{ - [ComponentInteraction("button")] - public static string Button() => "You clicked a button!"; -} diff --git a/Documentation/guides/services/component-interactions/Introduction/ChannelMenuModule.cs b/Documentation/guides/services/component-interactions/Introduction/ChannelMenuModule.cs deleted file mode 100644 index cd4f62b76..000000000 --- a/Documentation/guides/services/component-interactions/Introduction/ChannelMenuModule.cs +++ /dev/null @@ -1,9 +0,0 @@ -using NetCord.Services.ComponentInteractions; - -namespace MyBot; - -public class ChannelMenuModule : ComponentInteractionModule -{ - [ComponentInteraction("menu")] - public string Menu() => $"You selected: {string.Join(", ", Context.SelectedValues)}"; -} diff --git a/Documentation/guides/services/component-interactions/Introduction/Introduction.csproj b/Documentation/guides/services/component-interactions/Introduction/Introduction.csproj deleted file mode 100644 index 59b282e2d..000000000 --- a/Documentation/guides/services/component-interactions/Introduction/Introduction.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - Exe - - - - - - - - diff --git a/Documentation/guides/services/component-interactions/Introduction/MentionableMenuModule.cs b/Documentation/guides/services/component-interactions/Introduction/MentionableMenuModule.cs deleted file mode 100644 index 1bd486daf..000000000 --- a/Documentation/guides/services/component-interactions/Introduction/MentionableMenuModule.cs +++ /dev/null @@ -1,9 +0,0 @@ -using NetCord.Services.ComponentInteractions; - -namespace MyBot; - -public class MentionableMenuModule : ComponentInteractionModule -{ - [ComponentInteraction("menu")] - public string Menu() => $"You selected: {string.Join(", ", Context.SelectedValues)}"; -} diff --git a/Documentation/guides/services/component-interactions/Introduction/ModalModule.cs b/Documentation/guides/services/component-interactions/Introduction/ModalModule.cs deleted file mode 100644 index 71800bd90..000000000 --- a/Documentation/guides/services/component-interactions/Introduction/ModalModule.cs +++ /dev/null @@ -1,13 +0,0 @@ -using NetCord; -using NetCord.Services.ComponentInteractions; - -namespace MyBot; - -public class ModalModule : ComponentInteractionModule -{ - [ComponentInteraction("modal")] - public string Modal() => string.Join('\n', Context.Components.OfType