Skip to content

Commit

Permalink
fix: Handle failed Interactions properly
Browse files Browse the repository at this point in the history
  • Loading branch information
sabihoshi committed Dec 31, 2021
1 parent afb5f03 commit 0e4bd3c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions Zhongli.Services/Core/Listeners/InteractionHandlingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ public async Task InitializeAsync()
await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services);
}

private static Task ComponentCommandExecuted(ComponentCommandInfo info, IInteractionContext context, IResult result)
=> Task.CompletedTask;
private async Task ComponentCommandExecuted(ComponentCommandInfo info, IInteractionContext context, IResult result)
{
if (!result.IsSuccess)
await InteractionFailedAsync(context, result);
}

private static Task ContextCommandExecuted(ContextCommandInfo info, IInteractionContext context, IResult result)
=> Task.CompletedTask;
private async Task ContextCommandExecuted(ContextCommandInfo info, IInteractionContext context, IResult result)
{
if (!result.IsSuccess)
await InteractionFailedAsync(context, result);
}

private async Task InteractionFailedAsync(IInteractionContext context, IResult result)
{
Expand All @@ -75,10 +81,13 @@ private async Task InteractionFailedAsync(IInteractionContext context, IResult r
if (result.Error is not InteractionCommandError.UnknownCommand)
{
_log.LogError("{Error}: {ErrorReason}", result.Error, result.ErrorReason);
await context.Interaction.FollowupAsync(error, ephemeral: true);
await context.Interaction.RespondAsync(error, ephemeral: true);
}
}

private static Task SlashCommandExecuted(SlashCommandInfo info, IInteractionContext context, IResult result)
=> Task.CompletedTask;
private async Task SlashCommandExecuted(SlashCommandInfo info, IInteractionContext context, IResult result)
{
if (!result.IsSuccess)
await InteractionFailedAsync(context, result);
}
}

0 comments on commit 0e4bd3c

Please sign in to comment.