Skip to content

Commit 497918e

Browse files
committed
fix: raise CommandExecuted on async errors
This resolves #1224. Previously, raising CommandExecuted for errors was dependent on the failed result making it back to ExecuteAsync. This is not possible with async commands, which always pass back a succesful promise result, rather than their fulfilled result. This change moves the event invocation for exception'd ExecuteResults to their source, and excludes ExecuteResult from the late event invocation in CommandService#ExecuteAsync.
1 parent 552f34c commit 497918e

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/Discord.Net.Commands/CommandService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ float CalculateScore(CommandMatch match, ParseResult parseResult)
605605
//If we get this far, at least one parse was successful. Execute the most likely overload.
606606
var chosenOverload = successfulParses[0];
607607
var result = await chosenOverload.Key.ExecuteAsync(context, chosenOverload.Value, services).ConfigureAwait(false);
608-
if (!result.IsSuccess && !(result is RuntimeResult)) // succesful results raise the event in CommandInfo#ExecuteInternalAsync (have to raise it there b/c deffered execution)
608+
if (!result.IsSuccess && !(result is RuntimeResult || result is ExecuteResult)) // succesful results raise the event in CommandInfo#ExecuteInternalAsync (have to raise it there b/c deffered execution)
609609
await _commandExecutedEvent.InvokeAsync(chosenOverload.Key.Command, context, result);
610610
return result;
611611
}

src/Discord.Net.Commands/Info/CommandInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ private async Task<IResult> ExecuteInternalAsync(ICommandContext context, object
274274
await Module.Service._cmdLogger.ErrorAsync(wrappedEx).ConfigureAwait(false);
275275

276276
var result = ExecuteResult.FromError(ex);
277+
await Module.Service._commandExecutedEvent.InvokeAsync(this, context, result).ConfigureAwait(false);
277278

278279
if (Module.Service._throwOnError)
279280
{

0 commit comments

Comments
 (0)