private async Task CommandExecutionFailed(CommandExecutionFailedEventArgs e) { var context = (GarlicBreadCommandContext)e.Context; if (e.Result.Exception != null) { _logger.LogError(e.Result.Exception, "Exception during {0}.", e.Context.Command.Name); } await context.Channel.SendMessageAsync(e.Result.CommandExecutionStep + ": " + e.Result.Reason); }
private async Task CommandExecutionFailedAsync(CommandExecutionFailedEventArgs args) { var ctx = args.Context as ScrapContext; if (args.Result.Exception != null) { await logger.ReportErrorAsync(ctx.Message, args.Result.Exception); } var message = new LogMessage(LogSeverity.Warning, "CmdHandler", "An error occured while executing a command!", args.Result.Exception); await logger.LogAsync(message); }
private Task OnCommandExecutionFailed(CommandExecutionFailedEventArgs e) { var ctx = (AatroxCommandContext)e.Context; _logger.Error($"Command errored: {e.Context.Command.Name} by {ctx.User.Id} in {ctx.Guild.Id}", e.Result.Exception); var str = new StringBuilder(); switch (e.Result.Exception) { case DiscordHttpException ex when ex.HttpStatusCode == HttpStatusCode.Unauthorized: str.AppendLine("I don't have enough power to perform this action. (please check that the hierarchy of the bot is correct)"); break; case DiscordHttpException ex when ex.HttpStatusCode == HttpStatusCode.BadRequest: str.AppendLine($"The requested action has been stopped by Discord: `{ex.Message}`"); break; case DiscordHttpException ex: str.AppendLine($":angry: | Something bad happened: [{ex.HttpStatusCode}] {ex.Message}"); break; case ArgumentException ex: str.AppendLine($"{ex.Message}\n"); str.AppendLine($"Are you sure you didn't fail when typing the command? Please do `{ctx.Prefix}help {e.Result.Command.FullAliases[0]}`"); break; default: str.AppendLine($"{e.Result.Exception.GetType()} occured."); str.AppendLine($"{e.Result.Exception.Message}"); str.AppendLine($"{e.Result.Exception.StackTrace}"); _logger.Error($"{e.Result.Exception.GetType()} occured.", e.Result.Exception); break; } if (str.Length == 0) { return(Task.CompletedTask); } var embed = new LocalEmbedBuilder { Color = _configuration.DefaultEmbedColor, Title = "Something went wrong!" }; embed.AddField("__Command__", e.Result.Command.Name, true); embed.AddField("__Author__", ctx.User.FullName(), true); embed.AddField("__Error(s)__", str.ToString()); embed.WithFooter($"Type '{ctx.Prefix}help {ctx.Command.FullAliases[0].ToLowerInvariant()}' for more information."); return(ctx.Channel.SendMessageAsync("", false, embed.Build())); }
private Task CommandExecutionFailedAsync(CommandExecutionFailedEventArgs e) { if (e.Result.CommandExecutionStep == CommandExecutionStep.Command && e.Result.Exception is ContextTypeMismatchException contextTypeMismatchException) { var message = "A command context type mismatch occurred while attempting to execute {0}. " + "The module expected {1}, but got {2}."; var args = new List <object>(5) { e.Result.Command.Name, contextTypeMismatchException.ExpectedType, contextTypeMismatchException.ActualType }; // If the expected type is a DiscordGuildCommandContext, the actual type is a DiscordCommandContext, and the module doesn't have guild restrictions. if (typeof(DiscordGuildCommandContext).IsAssignableFrom(contextTypeMismatchException.ExpectedType) && typeof(DiscordCommandContext).IsAssignableFrom(contextTypeMismatchException.ActualType) && !CommandUtilities.EnumerateAllChecks(e.Result.Command.Module).Any(x => x is RequireGuildAttribute)) { message += " Did you forget to decorate the module with {3}?"; args.Add(nameof(RequireGuildAttribute)); } // If the expected type is a custom made context. if (contextTypeMismatchException.ExpectedType != typeof(DiscordGuildCommandContext) && contextTypeMismatchException.ExpectedType != typeof(DiscordCommandContext)) { message += " If you have not overridden {4}, you must do so and have it return the given context type. " + "Otherwise ensure it returns the correct context types."; args.Add(nameof(CreateCommandContext)); } Logger.LogError(message, args.ToArray()); } else { if (e.Result.Exception is OperationCanceledException && StoppingToken.IsCancellationRequested) { // Means the bot is stopping and any exceptions caused by cancellation we can ignore. return(Task.CompletedTask); } Logger.LogError(e.Result.Exception, e.Result.FailureReason); } if (e.Context is not DiscordCommandContext context) { return(Task.CompletedTask); } _ = InternalHandleFailedResultAsync(context, e.Result); return(Task.CompletedTask); }
private async Task OnCommandFailed(CommandExecutionFailedEventArgs e) { string msg = $"Failed executing command '{e.Result.Command.Name}'"; Logger.LogWarning(msg + "\n" + e.Result.Exception.ToString()); await((VCommandContext)e.Context).Message.GetChannel().SendMessageAsync ( new LocalMessageBuilder() .AddAttachment(new LocalAttachment(Encoding.ASCII.GetBytes(e.Result.Exception.ToString()), "error.txt")) .WithContent(msg) .Build() ); }
private Task CommandExecutionFailedAsync(CommandExecutionFailedEventArgs args) { var context = (RiasCommandContext)args.Context; var command = context.Command; var result = args.Result; Log.Error($"[Command] \"{command.Name}\"\n" + $"\t\t[Arguments] \"{context.RawArguments}\"\n" + $"\t\t[User] \"{context.User}\" ({context.User.Id})\n" + $"\t\t[Channel] \"{context.Channel.Name}\" ({context.Channel.Id})\n" + $"\t\t[Guild] \"{context.Guild?.Name ?? "DM"}\" ({context.Guild?.Id ?? 0})\n" + $"\t\t[Error Reason] {result.Reason}\n" + $"\t\t[Error Exception] {result.Exception}"); return(Task.CompletedTask); }
private async Task CommandExecutionFailedAsync(CommandExecutionFailedEventArgs e) { var context = e.Context as DiscordCommandContext; Logger.Log( $"Command Failed: {e.Context.Command.Name} {e.Result.CommandExecutionStep} {e.Result.Reason}\n" + $"{e.Result.Exception}", Logger.Source.Cmd); await context.Channel.SendMessageAsync( "", false, new LocalEmbedBuilder() .WithTitle($"Command Failed: {e.Context.Command.Name}") .AddField("Reason", e.Result.Exception.Message) .WithColor(Color.Red) .Build()); }
private ValueTask CommandExecutionFailedAsync(object sender, CommandExecutionFailedEventArgs args) { var context = (RiasCommandContext)args.Context; var command = context.Command; var result = args.Result; Log.Error(result.Exception, "{@Message}", new { Command = command.Name, Arguments = context.RawArguments, User = $"{context.User.FullName()} ({context.User.Id})", Channel = $"{context.Channel.Name} ({context.Channel.Id})", Guild = $"{context.Guild?.Name ?? "DM"} ({context.Guild?.Id ?? 0})", ErrorReason = result.FailureReason }); return(ValueTask.CompletedTask); }
private async Task CommandExecutionFailedAsync(CommandExecutionFailedEventArgs e) { var context = e.Context as DiscordCommandContext; Logger.Log("Command", $"Failed: {e.Context.Command.Name} {e.Result.CommandExecutionStep} {e.Result.Reason}\n" + $"{e.Result.Exception.StackTrace}", LogSeverity.Warning); bool response = true; #if DEBUG #else if (context.Guild != null) { using (var db = new DataContext()) { var guildConfig = db.Guilds.FirstOrDefault(x => x.GuildId == context.Guild.Id); if (guildConfig != null) { response = guildConfig.RespondOnCommandFailure; } } } #endif if (!response) { return; } await context.Channel.SendMessageAsync( "", false, new LocalEmbedBuilder() .WithTitle($"Command Failed: {e.Context.Command.Name}") .AddField("Reason", e.Result.Exception.Message) .WithColor(Color.Red) .Build()); }
private async Task OnCommandExecutionFailed(CommandExecutionFailedEventArgs e) { var context = (EspeonCommandContext)e.Context; await ExecutionFailedAsync(context, e.Result); }
private async Task CommandErroredAsync(CommandExecutionFailedEventArgs args) { var message = new LogMessage(LogSeverity.Warning, "CommandHandlerService", "An error occured while executing a command!", args.Result.Exception); await _logger.LogAsync(message); }
// In case of fuckup: private Task handler(CommandExecutionFailedEventArgs args) { Console.WriteLine(args.Result.Exception.ToString()); throw args.Result.Exception; }