1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-04-20 00:43:36 +03:00
Octobot/Commands/ErrorLoggingPostExecutionEvent.cs
Octol1ttle 946a860451
Add error logging to slash command handlers
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
2023-06-09 20:02:15 +05:00

24 lines
834 B
C#

using Microsoft.Extensions.Logging;
using Remora.Discord.Commands.Contexts;
using Remora.Discord.Commands.Services;
using Remora.Results;
// ReSharper disable ClassNeverInstantiated.Global
namespace Boyfriend.Commands;
public class ErrorLoggingPostExecutionEvent : IPostExecutionEvent {
private readonly ILogger<ErrorLoggingPostExecutionEvent> _logger;
public ErrorLoggingPostExecutionEvent(ILogger<ErrorLoggingPostExecutionEvent> logger) {
_logger = logger;
}
public Task<Result> AfterExecutionAsync(
ICommandContext context, IResult commandResult, CancellationToken ct = default) {
if (!commandResult.IsSuccess)
_logger.LogWarning("Error in slash command handler.\n{ErrorMessage}", commandResult.Error.Message);
return Task.FromResult(Result.FromSuccess());
}
}