diff --git a/Catalogger.Backend/Bot/Responders/CustomInteractionResponder.cs b/Catalogger.Backend/Bot/Responders/CustomInteractionResponder.cs index c07dc6d..1fd3b9e 100644 --- a/Catalogger.Backend/Bot/Responders/CustomInteractionResponder.cs +++ b/Catalogger.Backend/Bot/Responders/CustomInteractionResponder.cs @@ -19,17 +19,21 @@ using Remora.Commands.Services; using Remora.Commands.Tokenization; using Remora.Commands.Trees; using Remora.Discord.API.Abstractions.Gateway.Events; +using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Rest; +using Remora.Discord.API.Objects; using Remora.Discord.Commands.Responders; using Remora.Discord.Commands.Services; using Remora.Discord.Gateway.Responders; +using Remora.Rest.Core; using Remora.Results; using Serilog.Context; namespace Catalogger.Backend.Bot.Responders; /// -/// Wrapper for Remora.Discord's default interaction responder, that ignores all events if test mode is enabled. +/// Wrapper for Remora.Discord's default interaction responder, that ignores all events if test mode is enabled, +/// and handles results returned by commands. /// public class CustomInteractionResponder( Config config, @@ -87,6 +91,38 @@ public class CustomInteractionResponder( true ); - return await _inner.RespondAsync(evt, ct); + var result = await _inner.RespondAsync(evt, ct); + if (result.Error is not CataloggerError cataloggerError) + return result; + + return await interactionAPI.CreateInteractionResponseAsync( + evt.ID, + evt.Token, + new InteractionResponse( + Type: InteractionCallbackType.ChannelMessageWithSource, + Data: new Optional>( + new InteractionMessageCallbackData( + Embeds: new Optional>( + [ + new Embed( + Colour: DiscordUtils.Red, + Title: "Something went wrong", + Description: $""" + Something went wrong while running this command. + > {cataloggerError.Message} + Please try again later. + """ + ), + ] + ) + ) + ) + ), + ct: ct + ); } }