From 246282dda3a0b093041b2512c64bb5bbd2f9cb3c Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Mon, 1 Aug 2022 17:01:01 +0200 Subject: [PATCH] docs: Improve IF cmd execution docs (#2405) Adds samples and better explains workflow. --- docs/guides/int_framework/intro.md | 15 ++++++++++++++- docs/guides/int_framework/samples/intro/event.cs | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 docs/guides/int_framework/samples/intro/event.cs diff --git a/docs/guides/int_framework/intro.md b/docs/guides/int_framework/intro.md index 5d3253a6f..b51aa8088 100644 --- a/docs/guides/int_framework/intro.md +++ b/docs/guides/int_framework/intro.md @@ -308,8 +308,19 @@ Any of the following socket events can be used to execute commands: - [AutocompleteExecuted] - [UserCommandExecuted] - [MessageCommandExecuted] +- [ModalExecuted] -Commands can be either executed on the gateway thread or on a seperate thread from the thread pool. This behaviour can be configured by changing the *RunMode* property of `InteractionServiceConfig` or by setting the *runMode* parameter of a command attribute. +These events will trigger for the specific type of interaction they inherit their name from. The [InteractionCreated] event will trigger for all. +An example of executing a command from an event can be seen here: + +[!code-csharp[Command Event Example](samples/intro/event.cs)] + +Commands can be either executed on the gateway thread or on a seperate thread from the thread pool. +This behaviour can be configured by changing the `RunMode` property of `InteractionServiceConfig` or by setting the *runMode* parameter of a command attribute. + +> [!WARNING] +> In the example above, no form of post-execution is presented. +> Please carefully read the [Post Execution Documentation] for the best approach in resolving the result based on your `RunMode`. You can also configure the way [InteractionService] executes the commands. By default, commands are executed using `ConstructorInfo.Invoke()` to create module instances and @@ -364,6 +375,7 @@ delegate can be used to create HTTP responses from a deserialized json object st [AutocompleteHandlers]: xref:Guides.IntFw.AutoCompletion [DependencyInjection]: xref:Guides.TextCommands.DI +[Post Execution Docuemntation]: xref:Guides.IntFw.PostExecution [GroupAttribute]: xref:Discord.Interactions.GroupAttribute [InteractionService]: xref:Discord.Interactions.InteractionService @@ -376,6 +388,7 @@ delegate can be used to create HTTP responses from a deserialized json object st [AutocompleteExecuted]: xref:Discord.WebSocket.BaseSocketClient [UserCommandExecuted]: xref:Discord.WebSocket.BaseSocketClient [MessageCommandExecuted]: xref:Discord.WebSocket.BaseSocketClient +[ModalExecuted]: xref:Discord.WebSocket.BaseSocketClient [DiscordSocketClient]: xref:Discord.WebSocket.DiscordSocketClient [DiscordRestClient]: xref:Discord.Rest.DiscordRestClient [SocketInteractionContext]: xref:Discord.Interactions.SocketInteractionContext diff --git a/docs/guides/int_framework/samples/intro/event.cs b/docs/guides/int_framework/samples/intro/event.cs new file mode 100644 index 000000000..0c9f032b9 --- /dev/null +++ b/docs/guides/int_framework/samples/intro/event.cs @@ -0,0 +1,14 @@ +// Theres multiple ways to subscribe to the event, depending on your application. Please use the approach fit to your type of client. +// DiscordSocketClient: +_socketClient.InteractionCreated += async (x) => +{ + var ctx = new SocketInteractionContext(_socketClient, x); + await _interactionService.ExecuteCommandAsync(ctx, _serviceProvider); +} + +// DiscordShardedClient: +_shardedClient.InteractionCreated += async (x) => +{ + var ctx = new ShardedInteractionContext(_shardedClient, x); + await _interactionService.ExecuteCommandAsync(ctx, _serviceProvider); +}