diff --git a/docs/faq/commands/general.md b/docs/faq/commands/general.md index fb6fe39b6..de6d48dc1 100644 --- a/docs/faq/commands/general.md +++ b/docs/faq/commands/general.md @@ -119,24 +119,29 @@ The following are the known caveats with `RunMode.Async`, 3. [ExecuteAsync] will immediately return [ExecuteResult] instead of other result types (this is particularly important for those who wish to utilize [RuntimeResult] in 2.0). -4. Exceptions are swallowed. +4. Exceptions are swallowed in the `ExecuteAsync` result. However, there are ways to remedy some of these. For #3, in Discord.Net 2.0, the library introduces a new event called -[CommandExecuted], which is raised whenever the command is -**successfully executed**. This event will be raised regardless of -the `RunMode` type and will return the appropriate execution result. +[CommandService.CommandExecuted], which is raised whenever the command is executed. +This event will be raised regardless of +the `RunMode` type and will return the appropriate execution result +and the associated @Discord.Commands.CommandInfo if applicable. For #4, exceptions are caught in [CommandService.Log] event under -[LogMessage.Exception] as [CommandException]. +[LogMessage.Exception] as [CommandException] and in the +[CommandService.CommandExecuted] event under the [IResult] as +[ExecuteResult.Exception]. [Task.Run]: https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.run [async state machine]: https://www.red-gate.com/simple-talk/dotnet/net-tools/c-async-what-is-it-and-how-does-it-work/ [ExecuteAsync]: xref:Discord.Commands.CommandService.ExecuteAsync* [ExecuteResult]: xref:Discord.Commands.ExecuteResult [RuntimeResult]: xref:Discord.Commands.RuntimeResult -[CommandExecuted]: xref:Discord.Commands.CommandService.CommandExecuted +[CommandService.CommandExecuted]: xref:Discord.Commands.CommandService.CommandExecuted [CommandService.Log]: xref:Discord.Commands.CommandService.Log [LogMessage.Exception]: xref:Discord.LogMessage.Exception* -[CommandException]: xref:Discord.Commands.CommandException \ No newline at end of file +[ExecuteResult.Exception]: xref:Discord.Commands.ExecuteResult.Exception* +[CommandException]: xref:Discord.Commands.CommandException +[IResult]: xref:Discord.Commands.IResult \ No newline at end of file diff --git a/docs/guides/commands/post-execution.md b/docs/guides/commands/post-execution.md index 71f1801b3..bce29141f 100644 --- a/docs/guides/commands/post-execution.md +++ b/docs/guides/commands/post-execution.md @@ -31,13 +31,13 @@ be a violation of the SRP (Single Responsibility Principle). Another major issue is if your command is marked with `RunMode.Async`, [ExecuteAsync] will **always** return a successful [ExecuteResult] instead of the actual result. You can learn more -about the impact in the [FAQ](xref:FAQ.Commands.General). +about the impact in @FAQ.Commands.General. ## CommandExecuted Event Enter [CommandExecuted], an event that was introduced in Discord.Net 2.0. This event is raised whenever a command is -executed, regardless of its execution status. This means this +executed regardless of its execution status. This means this event can be used to streamline your post-execution design, and the best thing about this event is that it is not prone to `RunMode.Async`'s [ExecuteAsync] drawbacks. diff --git a/docs/guides/commands/samples/post-execution/command_executed_demo.cs b/docs/guides/commands/samples/post-execution/command_executed_demo.cs index 87ab40b5b..b0895f53d 100644 --- a/docs/guides/commands/samples/post-execution/command_executed_demo.cs +++ b/docs/guides/commands/samples/post-execution/command_executed_demo.cs @@ -30,10 +30,5 @@ public async Task HandleCommandAsync(SocketMessage msg) int argPos = 0; if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos)) || message.Author.IsBot) return; var context = new SocketCommandContext(_client, message); - var result = await _commands.ExecuteAsync(context, argPos, _services); - // Optionally, you may pass the result manually into your - // CommandExecuted event handler if you wish to handle parsing or - // precondition failures in the same method. - - // await OnCommandExecutedAsync(null, context, result); + await _commands.ExecuteAsync(context, argPos, _services); }