From 09e4679f2e3a2a4e65e1e95790ec2621673b9be8 Mon Sep 17 00:00:00 2001 From: csmir Date: Thu, 25 Jun 2026 20:06:16 +0200 Subject: [PATCH 01/16] Impl --- .../ApplicationCommandResultHandler.cs | 16 ++++++++----- .../Commands/CommandResultHandler.cs | 23 +++++++++++-------- .../ComponentInteractionResultHandler.cs | 17 +++++++++----- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs index d1a43fe6..ca428740 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -7,7 +7,7 @@ namespace NetCord.Hosting.Services.ApplicationCommands; -public class ApplicationCommandResultHandler(MessageFlags? messageFlags = null) +public class ApplicationCommandResultHandler : IApplicationCommandResultHandler where TContext : IApplicationCommandContext { @@ -25,12 +25,16 @@ public ValueTask HandleResultAsync(IExecutionResult result, TContext context, Ga else logger.LogDebug("Execution of an application command of name '{Name}' failed with '{Message}'", interaction.Data.Name, resultMessage); - InteractionMessageProperties message = new() + var messageProperties = GetFailMessage(failResult, context, services); + + return new(interaction.SendResponseAsync(InteractionCallback.Message(messageProperties))); + } + + public virtual InteractionMessageProperties GetFailMessage(IFailResult failResult, TContext context, IServiceProvider services) + { + return new() { - Content = resultMessage, - Flags = messageFlags, + Content = failResult.Message, }; - - return new(interaction.SendResponseAsync(InteractionCallback.Message(message))); } } diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs index cec72244..b744821f 100644 --- a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs @@ -1,12 +1,13 @@ using Microsoft.Extensions.Logging; using NetCord.Gateway; +using NetCord.Rest; using NetCord.Services; using NetCord.Services.Commands; namespace NetCord.Hosting.Services.Commands; -public class CommandResultHandler(MessageFlags? messageFlags = null) : ICommandResultHandler +public class CommandResultHandler : ICommandResultHandler where TContext : ICommandContext { public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient client, ILogger logger, IServiceProvider services) @@ -14,20 +15,24 @@ public ValueTask HandleResultAsync(IExecutionResult result, TContext context, Ga if (result is not IFailResult failResult) return default; - var resultMessage = failResult.Message; - var message = context.Message; if (failResult is IExceptionResult exceptionResult) logger.LogError(exceptionResult.Exception, "Execution of a command with content '{Content}' failed with an exception", message.Content); else - logger.LogDebug("Execution of a command with content '{Content}' failed with '{Message}'", message.Content, resultMessage); + logger.LogDebug("Execution of a command with content '{Content}' failed with '{Message}'", message.Content, failResult.Message); + + var messageProperties = GetFailMessage(failResult, context, services); - return new(message.ReplyAsync(new() + return new(client.Rest.SendMessageAsync(message.ChannelId, messageProperties)); + } + + public virtual MessageProperties GetFailMessage(IFailResult failResult, TContext context, IServiceProvider services) + { + return new() { - Content = resultMessage, - FailIfNotExists = false, - Flags = messageFlags, - })); + MessageReference = MessageReferenceProperties.Reply(context.Message.Id, false), + Content = failResult.Message, + }; } } diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs index 8f86a382..f44e6eb8 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -7,7 +7,8 @@ namespace NetCord.Hosting.Services.ComponentInteractions; -public class ComponentInteractionResultHandler(MessageFlags? messageFlags = null) : IComponentInteractionResultHandler +public class ComponentInteractionResultHandler + : IComponentInteractionResultHandler where TContext : IComponentInteractionContext { public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) @@ -24,12 +25,16 @@ public ValueTask HandleResultAsync(IExecutionResult result, TContext context, Ga else logger.LogDebug("Execution of an interaction of custom ID '{Id}' failed with '{Message}'", interaction.Data.CustomId, resultMessage); - InteractionMessageProperties message = new() + var messageProperties = GetFailMessage(failResult, context, services); + + return new(interaction.SendResponseAsync(InteractionCallback.Message(messageProperties))); + } + + public virtual InteractionMessageProperties GetFailMessage(IFailResult failResult, TContext context, IServiceProvider services) + { + return new() { - Content = resultMessage, - Flags = messageFlags, + Content = failResult.Message, }; - - return new(interaction.SendResponseAsync(InteractionCallback.Message(message))); } } From 482ece5d313e4552b80fa84b3d46309d4016cedd Mon Sep 17 00:00:00 2001 From: csmir Date: Thu, 25 Jun 2026 20:08:53 +0200 Subject: [PATCH 02/16] Fix test --- .../CustomApplicationCommandResultHandler.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs b/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs index 8e42f8d0..1f93844d 100644 --- a/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs +++ b/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs @@ -1,20 +1,18 @@ -using Microsoft.Extensions.Logging; - -using NetCord.Gateway; using NetCord.Hosting.Services.ApplicationCommands; +using NetCord.Rest; using NetCord.Services; using NetCord.Services.ApplicationCommands; namespace NetCord.Test.Hosting; -internal class CustomApplicationCommandResultHandler : IApplicationCommandResultHandler +internal class CustomApplicationCommandResultHandler : ApplicationCommandResultHandler { - private static readonly ApplicationCommandResultHandler _defaultHandler = new(MessageFlags.Ephemeral); - - public ValueTask HandleResultAsync(IExecutionResult result, ApplicationCommandContext context, GatewayClient? client, ILogger logger, IServiceProvider services) + public override InteractionMessageProperties GetFailMessage(IFailResult failResult, ApplicationCommandContext context, IServiceProvider services) { - logger.LogInformation("Handling result of an application command"); + var message = base.GetFailMessage(failResult, context, services); + + message.WithFlags(MessageFlags.Ephemeral); - return _defaultHandler.HandleResultAsync(result, context, client, logger, services); + return message; } } From 1a0910bf9587c0b4600324f6eaa62fd794e61ef4 Mon Sep 17 00:00:00 2001 From: csmir Date: Thu, 25 Jun 2026 20:46:15 +0200 Subject: [PATCH 03/16] Create and target defaults on result handlers --- .../ApplicationCommandInteractionHandler.cs | 2 +- .../ApplicationCommandResultHandler.cs | 21 +++++++++++++++++ .../Commands/CommandHandler.cs | 2 +- .../Commands/CommandResultHandler.cs | 7 ++++++ .../ComponentInteractionHandler.cs | 2 +- .../ComponentInteractionResultHandler.cs | 23 +++++++++++++++++++ 6 files changed, 54 insertions(+), 3 deletions(-) diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandInteractionHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandInteractionHandler.cs index 37252124..57b8ccae 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandInteractionHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandInteractionHandler.cs @@ -48,7 +48,7 @@ public ApplicationCommandInteractionHandler(IServiceProvider services, _handleAsync = &HandleInteractionAsync; _createContext = optionsValue.CreateContext ?? ContextHelper.CreateContextDelegate(_applicationCommandService.Configuration.ServiceResolverProvider); - _resultHandler = optionsValue.ResultHandler ?? new ApplicationCommandResultHandler(); + _resultHandler = optionsValue.ResultHandler ?? ApplicationCommandResultHandler.Default; _preExecutionHandler = optionsValue.PreExecutionHandler ?? new ApplicationCommandPreExecutionHandler(); _client = client; } diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs index ca428740..23a8e223 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -11,6 +11,27 @@ public class ApplicationCommandResultHandler : IApplicationCommandResultHandler where TContext : IApplicationCommandContext { + public static ApplicationCommandResultHandler Ephemeral + => new EphemeralApplicationCommandResultHandler(); + + public static ApplicationCommandResultHandler Default + => new(); + + protected ApplicationCommandResultHandler() + { + } + + internal class EphemeralApplicationCommandResultHandler : ApplicationCommandResultHandler + where T : IApplicationCommandContext + { + public override InteractionMessageProperties GetFailMessage(IFailResult failResult, T context, IServiceProvider services) + { + var message = base.GetFailMessage(failResult, context, services); + message.WithFlags(MessageFlags.Ephemeral); + return message; + } + } + public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) { if (result is not IFailResult failResult) diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandHandler.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandHandler.cs index af89d1e4..fb112655 100644 --- a/Hosting/NetCord.Hosting.Services/Commands/CommandHandler.cs +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandHandler.cs @@ -49,7 +49,7 @@ public CommandHandler(IServiceProvider services, _getCommandTextAsync = GetGetCommandTextAsyncDelegate(optionsValue); _createContext = optionsValue.CreateContext ?? ContextHelper.CreateContextDelegate(_commandService.Configuration.ServiceResolverProvider); - _resultHandler = optionsValue.ResultHandler ?? new CommandResultHandler(); + _resultHandler = optionsValue.ResultHandler ?? CommandResultHandler.Default; _preExecutionHandler = optionsValue.PreExecutionHandler ?? new CommandPreExecutionHandler(); _client = client; } diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs index b744821f..9a1092f9 100644 --- a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs @@ -10,6 +10,13 @@ namespace NetCord.Hosting.Services.Commands; public class CommandResultHandler : ICommandResultHandler where TContext : ICommandContext { + public static CommandResultHandler Default + => new(); + + protected CommandResultHandler() + { + } + public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient client, ILogger logger, IServiceProvider services) { if (result is not IFailResult failResult) diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionHandler.cs index 7dd5d755..3c80ef02 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionHandler.cs @@ -49,7 +49,7 @@ public ComponentInteractionHandler(IServiceProvider services, _handleAsync = &HandleInteractionAsync; _createContext = optionsValue.CreateContext ?? ContextHelper.CreateContextDelegate(_componentInteractionService.Configuration.ServiceResolverProvider); - _resultHandler = optionsValue.ResultHandler ?? new ComponentInteractionResultHandler(); + _resultHandler = optionsValue.ResultHandler ?? ComponentInteractionResultHandler.Default; _preExecutionHandler = optionsValue.PreExecutionHandler ?? new ComponentInteractionPreExecutionHandler(); _client = client; } diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs index f44e6eb8..8fe86e43 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -1,8 +1,10 @@ using Microsoft.Extensions.Logging; using NetCord.Gateway; +using NetCord.Hosting.Services.ApplicationCommands; using NetCord.Rest; using NetCord.Services; +using NetCord.Services.ApplicationCommands; using NetCord.Services.ComponentInteractions; namespace NetCord.Hosting.Services.ComponentInteractions; @@ -11,6 +13,27 @@ public class ComponentInteractionResultHandler : IComponentInteractionResultHandler where TContext : IComponentInteractionContext { + public static ComponentInteractionResultHandler Ephemeral + => new EphemeralComponentInteractionResultHandler(); + + public static ComponentInteractionResultHandler Default + => new(); + + protected ComponentInteractionResultHandler() + { + } + + internal class EphemeralComponentInteractionResultHandler : ComponentInteractionResultHandler + where T : IComponentInteractionContext + { + public override InteractionMessageProperties GetFailMessage(IFailResult failResult, T context, IServiceProvider services) + { + var message = base.GetFailMessage(failResult, context, services); + message.WithFlags(MessageFlags.Ephemeral); + return message; + } + } + public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) { if (result is not IFailResult failResult) From 58aad249479848d85d6d303fb482d7237bcfead1 Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+csmir@users.noreply.github.com> Date: Fri, 26 Jun 2026 00:33:07 +0200 Subject: [PATCH 04/16] Update Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs Co-authored-by: Kuba_Z2 <77853483+KubaZ2@users.noreply.github.com> --- .../ApplicationCommands/ApplicationCommandResultHandler.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs index 23a8e223..2f9f9940 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -11,11 +11,9 @@ public class ApplicationCommandResultHandler : IApplicationCommandResultHandler where TContext : IApplicationCommandContext { - public static ApplicationCommandResultHandler Ephemeral - => new EphemeralApplicationCommandResultHandler(); + public static ApplicationCommandResultHandler Default => new(); - public static ApplicationCommandResultHandler Default - => new(); + public static ApplicationCommandResultHandler Ephemeral => new EphemeralApplicationCommandResultHandler(); protected ApplicationCommandResultHandler() { From 2cbf9a88a16cc80b1b09522e8a9eb5676814360b Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+csmir@users.noreply.github.com> Date: Fri, 26 Jun 2026 00:33:16 +0200 Subject: [PATCH 05/16] Update Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs Co-authored-by: Kuba_Z2 <77853483+KubaZ2@users.noreply.github.com> --- .../ApplicationCommands/ApplicationCommandResultHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs index 2f9f9940..c900a25a 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -25,7 +25,7 @@ internal class EphemeralApplicationCommandResultHandler : ApplicationCommandR public override InteractionMessageProperties GetFailMessage(IFailResult failResult, T context, IServiceProvider services) { var message = base.GetFailMessage(failResult, context, services); - message.WithFlags(MessageFlags.Ephemeral); + message.Flags = MessageFlags.Ephemeral; return message; } } From 4dc8c0399d5330605b99d0833e2e24b36ad7ac83 Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+csmir@users.noreply.github.com> Date: Fri, 26 Jun 2026 00:33:22 +0200 Subject: [PATCH 06/16] Update Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs Co-authored-by: Kuba_Z2 <77853483+KubaZ2@users.noreply.github.com> --- .../NetCord.Hosting.Services/Commands/CommandResultHandler.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs index 9a1092f9..a179f30b 100644 --- a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs @@ -10,8 +10,7 @@ namespace NetCord.Hosting.Services.Commands; public class CommandResultHandler : ICommandResultHandler where TContext : ICommandContext { - public static CommandResultHandler Default - => new(); + public static CommandResultHandler Default => new(); protected CommandResultHandler() { From 3e5751d38585b203575a0e3e81fa06b99cffff0b Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+csmir@users.noreply.github.com> Date: Fri, 26 Jun 2026 00:33:29 +0200 Subject: [PATCH 07/16] Update Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs Co-authored-by: Kuba_Z2 <77853483+KubaZ2@users.noreply.github.com> --- .../ComponentInteractions/ComponentInteractionResultHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs index 8fe86e43..c7ce7640 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -23,7 +23,7 @@ protected ComponentInteractionResultHandler() { } - internal class EphemeralComponentInteractionResultHandler : ComponentInteractionResultHandler + private class EphemeralComponentInteractionResultHandler : ComponentInteractionResultHandler where T : IComponentInteractionContext { public override InteractionMessageProperties GetFailMessage(IFailResult failResult, T context, IServiceProvider services) From ab421aa5e7825164d15f595152059be3a69ad188 Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+csmir@users.noreply.github.com> Date: Fri, 26 Jun 2026 00:33:38 +0200 Subject: [PATCH 08/16] Update Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs Co-authored-by: Kuba_Z2 <77853483+KubaZ2@users.noreply.github.com> --- .../ComponentInteractions/ComponentInteractionResultHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs index c7ce7640..7e50c43f 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -29,7 +29,7 @@ private class EphemeralComponentInteractionResultHandler : ComponentInteracti public override InteractionMessageProperties GetFailMessage(IFailResult failResult, T context, IServiceProvider services) { var message = base.GetFailMessage(failResult, context, services); - message.WithFlags(MessageFlags.Ephemeral); + message.Flags = MessageFlags.Ephemeral; return message; } } From a607ebf559f0e1a49767e623065e30c7de66fbd4 Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+csmir@users.noreply.github.com> Date: Fri, 26 Jun 2026 00:33:46 +0200 Subject: [PATCH 09/16] Update Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs Co-authored-by: Kuba_Z2 <77853483+KubaZ2@users.noreply.github.com> --- .../ComponentInteractionResultHandler.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs index 7e50c43f..d188b6d0 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -13,11 +13,9 @@ public class ComponentInteractionResultHandler : IComponentInteractionResultHandler where TContext : IComponentInteractionContext { - public static ComponentInteractionResultHandler Ephemeral - => new EphemeralComponentInteractionResultHandler(); + public static ComponentInteractionResultHandler Default => new(); - public static ComponentInteractionResultHandler Default - => new(); + public static ComponentInteractionResultHandler Ephemeral => new EphemeralComponentInteractionResultHandler(); protected ComponentInteractionResultHandler() { From 8b0065cb2a467249e3b363b1786d7a6aed27f749 Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+csmir@users.noreply.github.com> Date: Fri, 26 Jun 2026 00:34:05 +0200 Subject: [PATCH 10/16] Update Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs Co-authored-by: Kuba_Z2 <77853483+KubaZ2@users.noreply.github.com> --- .../ApplicationCommands/ApplicationCommandResultHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs index c900a25a..66c6f427 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -19,7 +19,7 @@ protected ApplicationCommandResultHandler() { } - internal class EphemeralApplicationCommandResultHandler : ApplicationCommandResultHandler + private class EphemeralApplicationCommandResultHandler : ApplicationCommandResultHandler where T : IApplicationCommandContext { public override InteractionMessageProperties GetFailMessage(IFailResult failResult, T context, IServiceProvider services) From 21c98754333f43bbb0ed92384838eb22300d90aa Mon Sep 17 00:00:00 2001 From: csmir Date: Fri, 26 Jun 2026 00:51:44 +0200 Subject: [PATCH 11/16] Swap out to async --- .../ApplicationCommandResultHandler.cs | 18 ++++++++--------- .../Commands/CommandResultHandler.cs | 14 ++++++------- .../ComponentInteractionResultHandler.cs | 20 +++++++++---------- .../CustomApplicationCommandResultHandler.cs | 4 ++-- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs index 66c6f427..cbe989e2 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -22,18 +22,18 @@ protected ApplicationCommandResultHandler() private class EphemeralApplicationCommandResultHandler : ApplicationCommandResultHandler where T : IApplicationCommandContext { - public override InteractionMessageProperties GetFailMessage(IFailResult failResult, T context, IServiceProvider services) + public override async ValueTask GetFailMessageAsync(IFailResult failResult, T context, IServiceProvider services) { - var message = base.GetFailMessage(failResult, context, services); + var message = await base.GetFailMessageAsync(failResult, context, services).ConfigureAwait(false); message.Flags = MessageFlags.Ephemeral; return message; } } - public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) + public async ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) { if (result is not IFailResult failResult) - return default; + return; var resultMessage = failResult.Message; @@ -44,16 +44,16 @@ public ValueTask HandleResultAsync(IExecutionResult result, TContext context, Ga else logger.LogDebug("Execution of an application command of name '{Name}' failed with '{Message}'", interaction.Data.Name, resultMessage); - var messageProperties = GetFailMessage(failResult, context, services); + var messageProperties = await GetFailMessageAsync(failResult, context, services).ConfigureAwait(false); - return new(interaction.SendResponseAsync(InteractionCallback.Message(messageProperties))); + await interaction.SendResponseAsync(InteractionCallback.Message(messageProperties)).ConfigureAwait(false); } - public virtual InteractionMessageProperties GetFailMessage(IFailResult failResult, TContext context, IServiceProvider services) + public virtual ValueTask GetFailMessageAsync(IFailResult failResult, TContext context, IServiceProvider services) { - return new() + return new(new InteractionMessageProperties { Content = failResult.Message, - }; + }); } } diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs index a179f30b..1bad1fa7 100644 --- a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs @@ -16,10 +16,10 @@ protected CommandResultHandler() { } - public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient client, ILogger logger, IServiceProvider services) + public async ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient client, ILogger logger, IServiceProvider services) { if (result is not IFailResult failResult) - return default; + return; var message = context.Message; @@ -28,17 +28,17 @@ public ValueTask HandleResultAsync(IExecutionResult result, TContext context, Ga else logger.LogDebug("Execution of a command with content '{Content}' failed with '{Message}'", message.Content, failResult.Message); - var messageProperties = GetFailMessage(failResult, context, services); + var messageProperties = await GetFailMessage(failResult, context, services).ConfigureAwait(false); - return new(client.Rest.SendMessageAsync(message.ChannelId, messageProperties)); + await client.Rest.SendMessageAsync(message.ChannelId, messageProperties).ConfigureAwait(false); } - public virtual MessageProperties GetFailMessage(IFailResult failResult, TContext context, IServiceProvider services) + public virtual ValueTask GetFailMessage(IFailResult failResult, TContext context, IServiceProvider services) { - return new() + return new(new MessageProperties { MessageReference = MessageReferenceProperties.Reply(context.Message.Id, false), Content = failResult.Message, - }; + }); } } diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs index d188b6d0..0efab1ac 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -1,10 +1,8 @@ using Microsoft.Extensions.Logging; using NetCord.Gateway; -using NetCord.Hosting.Services.ApplicationCommands; using NetCord.Rest; using NetCord.Services; -using NetCord.Services.ApplicationCommands; using NetCord.Services.ComponentInteractions; namespace NetCord.Hosting.Services.ComponentInteractions; @@ -24,18 +22,18 @@ protected ComponentInteractionResultHandler() private class EphemeralComponentInteractionResultHandler : ComponentInteractionResultHandler where T : IComponentInteractionContext { - public override InteractionMessageProperties GetFailMessage(IFailResult failResult, T context, IServiceProvider services) + public override async ValueTask GetFailMessageAsync(IFailResult failResult, T context, IServiceProvider services) { - var message = base.GetFailMessage(failResult, context, services); + var message = await base.GetFailMessageAsync(failResult, context, services).ConfigureAwait(false); message.Flags = MessageFlags.Ephemeral; return message; } } - public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) + public async ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) { if (result is not IFailResult failResult) - return default; + return; var resultMessage = failResult.Message; @@ -46,16 +44,16 @@ public ValueTask HandleResultAsync(IExecutionResult result, TContext context, Ga else logger.LogDebug("Execution of an interaction of custom ID '{Id}' failed with '{Message}'", interaction.Data.CustomId, resultMessage); - var messageProperties = GetFailMessage(failResult, context, services); + var messageProperties = await GetFailMessageAsync(failResult, context, services).ConfigureAwait(false); - return new(interaction.SendResponseAsync(InteractionCallback.Message(messageProperties))); + await interaction.SendResponseAsync(InteractionCallback.Message(messageProperties)).ConfigureAwait(false); } - public virtual InteractionMessageProperties GetFailMessage(IFailResult failResult, TContext context, IServiceProvider services) + public virtual ValueTask GetFailMessageAsync(IFailResult failResult, TContext context, IServiceProvider services) { - return new() + return new(new InteractionMessageProperties { Content = failResult.Message, - }; + }); } } diff --git a/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs b/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs index 1f93844d..32cd0f5b 100644 --- a/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs +++ b/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs @@ -7,9 +7,9 @@ namespace NetCord.Test.Hosting; internal class CustomApplicationCommandResultHandler : ApplicationCommandResultHandler { - public override InteractionMessageProperties GetFailMessage(IFailResult failResult, ApplicationCommandContext context, IServiceProvider services) + public override async ValueTask GetFailMessageAsync(IFailResult failResult, ApplicationCommandContext context, IServiceProvider services) { - var message = base.GetFailMessage(failResult, context, services); + var message = await base.GetFailMessageAsync(failResult, context, services).ConfigureAwait(false); message.WithFlags(MessageFlags.Ephemeral); From 0ccc78234f22e2742d719b6ba143e8f419fcbe7d Mon Sep 17 00:00:00 2001 From: csmir Date: Fri, 26 Jun 2026 18:51:31 +0200 Subject: [PATCH 12/16] 'Inline' await consumer to prevent extra async call --- .../ApplicationCommandResultHandler.cs | 10 ++++++---- .../ComponentInteractionResultHandler.cs | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs index cbe989e2..67b29594 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -22,11 +22,13 @@ protected ApplicationCommandResultHandler() private class EphemeralApplicationCommandResultHandler : ApplicationCommandResultHandler where T : IApplicationCommandContext { - public override async ValueTask GetFailMessageAsync(IFailResult failResult, T context, IServiceProvider services) + public override ValueTask GetFailMessageAsync(IFailResult failResult, T context, IServiceProvider services) { - var message = await base.GetFailMessageAsync(failResult, context, services).ConfigureAwait(false); - message.Flags = MessageFlags.Ephemeral; - return message; + return new(new InteractionMessageProperties + { + Content = failResult.Message, + Flags = MessageFlags.Ephemeral, + }); } } diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs index 0efab1ac..51722fde 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -22,11 +22,13 @@ protected ComponentInteractionResultHandler() private class EphemeralComponentInteractionResultHandler : ComponentInteractionResultHandler where T : IComponentInteractionContext { - public override async ValueTask GetFailMessageAsync(IFailResult failResult, T context, IServiceProvider services) + public override ValueTask GetFailMessageAsync(IFailResult failResult, T context, IServiceProvider services) { - var message = await base.GetFailMessageAsync(failResult, context, services).ConfigureAwait(false); - message.Flags = MessageFlags.Ephemeral; - return message; + return new(new InteractionMessageProperties + { + Content = failResult.Message, + Flags = MessageFlags.Ephemeral, + }); } } From 479a96f309a2b7757cf060b8e5f495658e89f59f Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+csmir@users.noreply.github.com> Date: Fri, 26 Jun 2026 19:13:40 +0200 Subject: [PATCH 13/16] Apply suggestions from code review Co-authored-by: Kuba_Z2 <77853483+KubaZ2@users.noreply.github.com> --- .../ApplicationCommands/ApplicationCommandResultHandler.cs | 2 +- .../NetCord.Hosting.Services/Commands/CommandResultHandler.cs | 2 +- .../ComponentInteractions/ComponentInteractionResultHandler.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs index 67b29594..cf8ed0b8 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -19,7 +19,7 @@ protected ApplicationCommandResultHandler() { } - private class EphemeralApplicationCommandResultHandler : ApplicationCommandResultHandler + private sealed class EphemeralApplicationCommandResultHandler : ApplicationCommandResultHandler where T : IApplicationCommandContext { public override ValueTask GetFailMessageAsync(IFailResult failResult, T context, IServiceProvider services) diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs index 1bad1fa7..34f0221c 100644 --- a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs @@ -30,7 +30,7 @@ public async ValueTask HandleResultAsync(IExecutionResult result, TContext conte var messageProperties = await GetFailMessage(failResult, context, services).ConfigureAwait(false); - await client.Rest.SendMessageAsync(message.ChannelId, messageProperties).ConfigureAwait(false); + await message.SendAsync(messageProperties).ConfigureAwait(false); } public virtual ValueTask GetFailMessage(IFailResult failResult, TContext context, IServiceProvider services) diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs index 51722fde..483ecc19 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -19,7 +19,7 @@ protected ComponentInteractionResultHandler() { } - private class EphemeralComponentInteractionResultHandler : ComponentInteractionResultHandler + private sealed class EphemeralComponentInteractionResultHandler : ComponentInteractionResultHandler where T : IComponentInteractionContext { public override ValueTask GetFailMessageAsync(IFailResult failResult, T context, IServiceProvider services) From add6e24c309761e72de5fbcaeb3908c730459560 Mon Sep 17 00:00:00 2001 From: KubaZ2 Date: Sat, 27 Jun 2026 11:35:15 +0200 Subject: [PATCH 14/16] Refactor --- .../ApplicationCommandResultHandler.cs | 12 ++++++------ .../Commands/CommandResultHandler.cs | 10 ++++++---- .../ComponentInteractionResultHandler.cs | 14 +++++++------- .../CustomApplicationCommandResultHandler.cs | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs index cf8ed0b8..109dd4c4 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -37,18 +37,18 @@ public async ValueTask HandleResultAsync(IExecutionResult result, TContext conte if (result is not IFailResult failResult) return; - var resultMessage = failResult.Message; - var interaction = context.Interaction; + var commandName = interaction.Data.Name; + if (failResult is IExceptionResult exceptionResult) - logger.LogError(exceptionResult.Exception, "Execution of an application command of name '{Name}' failed with an exception", interaction.Data.Name); + logger.LogError(exceptionResult.Exception, "Execution of an application command of name '{Name}' failed with an exception", commandName); else - logger.LogDebug("Execution of an application command of name '{Name}' failed with '{Message}'", interaction.Data.Name, resultMessage); + logger.LogDebug("Execution of an application command of name '{Name}' failed with '{Message}'", commandName, failResult.Message); - var messageProperties = await GetFailMessageAsync(failResult, context, services).ConfigureAwait(false); + var response = await GetFailMessageAsync(failResult, context, services).ConfigureAwait(false); - await interaction.SendResponseAsync(InteractionCallback.Message(messageProperties)).ConfigureAwait(false); + await interaction.SendResponseAsync(InteractionCallback.Message(response)).ConfigureAwait(false); } public virtual ValueTask GetFailMessageAsync(IFailResult failResult, TContext context, IServiceProvider services) diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs index 34f0221c..5df9d17a 100644 --- a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs @@ -23,14 +23,16 @@ public async ValueTask HandleResultAsync(IExecutionResult result, TContext conte var message = context.Message; + var messageContent = message.Content; + if (failResult is IExceptionResult exceptionResult) - logger.LogError(exceptionResult.Exception, "Execution of a command with content '{Content}' failed with an exception", message.Content); + logger.LogError(exceptionResult.Exception, "Execution of a command with content '{Content}' failed with an exception", messageContent); else - logger.LogDebug("Execution of a command with content '{Content}' failed with '{Message}'", message.Content, failResult.Message); + logger.LogDebug("Execution of a command with content '{Content}' failed with '{Message}'", messageContent, failResult.Message); - var messageProperties = await GetFailMessage(failResult, context, services).ConfigureAwait(false); + var response = await GetFailMessage(failResult, context, services).ConfigureAwait(false); - await message.SendAsync(messageProperties).ConfigureAwait(false); + await message.SendAsync(response).ConfigureAwait(false); } public virtual ValueTask GetFailMessage(IFailResult failResult, TContext context, IServiceProvider services) diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs index 483ecc19..bdb03c6a 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -7,7 +7,7 @@ namespace NetCord.Hosting.Services.ComponentInteractions; -public class ComponentInteractionResultHandler +public class ComponentInteractionResultHandler : IComponentInteractionResultHandler where TContext : IComponentInteractionContext { @@ -37,18 +37,18 @@ public async ValueTask HandleResultAsync(IExecutionResult result, TContext conte if (result is not IFailResult failResult) return; - var resultMessage = failResult.Message; - var interaction = context.Interaction; + var customId = interaction.Data.CustomId; + if (failResult is IExceptionResult exceptionResult) - logger.LogError(exceptionResult.Exception, "Execution of an interaction of custom ID '{Id}' failed with an exception", interaction.Data.CustomId); + logger.LogError(exceptionResult.Exception, "Execution of an interaction of custom ID '{Id}' failed with an exception", customId); else - logger.LogDebug("Execution of an interaction of custom ID '{Id}' failed with '{Message}'", interaction.Data.CustomId, resultMessage); + logger.LogDebug("Execution of an interaction of custom ID '{Id}' failed with '{Message}'", customId, failResult.Message); - var messageProperties = await GetFailMessageAsync(failResult, context, services).ConfigureAwait(false); + var response = await GetFailMessageAsync(failResult, context, services).ConfigureAwait(false); - await interaction.SendResponseAsync(InteractionCallback.Message(messageProperties)).ConfigureAwait(false); + await interaction.SendResponseAsync(InteractionCallback.Message(response)).ConfigureAwait(false); } public virtual ValueTask GetFailMessageAsync(IFailResult failResult, TContext context, IServiceProvider services) diff --git a/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs b/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs index 32cd0f5b..f1e0eabe 100644 --- a/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs +++ b/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs @@ -11,7 +11,7 @@ public override async ValueTask GetFailMessageAsyn { var message = await base.GetFailMessageAsync(failResult, context, services).ConfigureAwait(false); - message.WithFlags(MessageFlags.Ephemeral); + message.Flags = MessageFlags.Ephemeral; return message; } From 956c2285448604b54890af3429dd66b819be9324 Mon Sep 17 00:00:00 2001 From: KubaZ2 Date: Sat, 27 Jun 2026 12:18:17 +0200 Subject: [PATCH 15/16] Remove useless generic --- .../ApplicationCommandResultHandler.cs | 10 ++++------ .../ComponentInteractionResultHandler.cs | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs index 109dd4c4..359db5ed 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -7,22 +7,20 @@ namespace NetCord.Hosting.Services.ApplicationCommands; -public class ApplicationCommandResultHandler - : IApplicationCommandResultHandler +public class ApplicationCommandResultHandler : IApplicationCommandResultHandler where TContext : IApplicationCommandContext { public static ApplicationCommandResultHandler Default => new(); - public static ApplicationCommandResultHandler Ephemeral => new EphemeralApplicationCommandResultHandler(); + public static ApplicationCommandResultHandler Ephemeral => new EphemeralApplicationCommandResultHandler(); protected ApplicationCommandResultHandler() { } - private sealed class EphemeralApplicationCommandResultHandler : ApplicationCommandResultHandler - where T : IApplicationCommandContext + private sealed class EphemeralApplicationCommandResultHandler : ApplicationCommandResultHandler { - public override ValueTask GetFailMessageAsync(IFailResult failResult, T context, IServiceProvider services) + public override ValueTask GetFailMessageAsync(IFailResult failResult, TContext context, IServiceProvider services) { return new(new InteractionMessageProperties { diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs index bdb03c6a..c5e4d4a7 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -7,22 +7,20 @@ namespace NetCord.Hosting.Services.ComponentInteractions; -public class ComponentInteractionResultHandler - : IComponentInteractionResultHandler +public class ComponentInteractionResultHandler : IComponentInteractionResultHandler where TContext : IComponentInteractionContext { public static ComponentInteractionResultHandler Default => new(); - public static ComponentInteractionResultHandler Ephemeral => new EphemeralComponentInteractionResultHandler(); + public static ComponentInteractionResultHandler Ephemeral => new EphemeralComponentInteractionResultHandler(); protected ComponentInteractionResultHandler() { } - private sealed class EphemeralComponentInteractionResultHandler : ComponentInteractionResultHandler - where T : IComponentInteractionContext + private sealed class EphemeralComponentInteractionResultHandler : ComponentInteractionResultHandler { - public override ValueTask GetFailMessageAsync(IFailResult failResult, T context, IServiceProvider services) + public override ValueTask GetFailMessageAsync(IFailResult failResult, TContext context, IServiceProvider services) { return new(new InteractionMessageProperties { From 07dd0861b6c5bccb1590b889f79e2a84fe02ed5d Mon Sep 17 00:00:00 2001 From: KubaZ2 Date: Sat, 27 Jun 2026 12:46:39 +0200 Subject: [PATCH 16/16] Refactor CustomApplicationCommandResultHandler --- .../CustomApplicationCommandResultHandler.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs b/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs index f1e0eabe..5b08db80 100644 --- a/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs +++ b/Tests/NetCord.Test.Hosting/CustomApplicationCommandResultHandler.cs @@ -1,18 +1,20 @@ +using Microsoft.Extensions.Logging; + +using NetCord.Gateway; using NetCord.Hosting.Services.ApplicationCommands; -using NetCord.Rest; using NetCord.Services; using NetCord.Services.ApplicationCommands; namespace NetCord.Test.Hosting; -internal class CustomApplicationCommandResultHandler : ApplicationCommandResultHandler +internal class CustomApplicationCommandResultHandler : IApplicationCommandResultHandler { - public override async ValueTask GetFailMessageAsync(IFailResult failResult, ApplicationCommandContext context, IServiceProvider services) - { - var message = await base.GetFailMessageAsync(failResult, context, services).ConfigureAwait(false); + private static readonly ApplicationCommandResultHandler _defaultHandler = ApplicationCommandResultHandler.Ephemeral; - message.Flags = MessageFlags.Ephemeral; + public ValueTask HandleResultAsync(IExecutionResult result, ApplicationCommandContext context, GatewayClient? client, ILogger logger, IServiceProvider services) + { + logger.LogInformation("Handling result of an application command"); - return message; + return _defaultHandler.HandleResultAsync(result, context, client, logger, services); } }