Exemple #1
0
 private static async Task Commands_CommandErrored(CommandErrorEventArgs e)
 {
     if (e.Context.Channel.Get(ConfigManager.Enabled).True())
     {
         if (e.Exception is UnwantedExecutionException)
         {
             return;
         }
         e.Context.Client.DebugLogger.LogMessage(LogLevel.Error, "DiscHax",
                                                 $"{e.Context.User.Username} tried executing '{e.Command?.QualifiedName ?? "<unknown command>"}' but it errored: {e.Exception}",
                                                 DateTime.Now);
         if (e.Exception is ChecksFailedException)
         {
             await e.Context.RespondAsync(embed : new DiscordEmbedBuilder
             {
                 Title       = "Access denied",
                 Description =
                     $"{DiscordEmoji.FromName(e.Context.Client, ":no_entry:")} You do not have the permissions required to execute this command.",
                 Color = new DiscordColor(0xFF0000)
             }.Build());
         }
         else if (!(e.Exception is CommandNotFoundException))
         {
             await e.Context.RespondAsyncFix($"The command failed: {e.Exception.Message}");
         }
     }
 }
        private async Task DiscordCommands_CommandErrored(CommandErrorEventArgs e)
        {
            if (e.Exception is CommandNotFoundException)
            {
                return;
            }

            this.Discord.DebugLogger.LogMessage(LogLevel.Error, "CommandsNext", string.Concat(e.Exception.GetType(), ": ", e.Exception.Message), DateTime.Now);

            var ms = e.Exception.Message;
            var st = e.Exception.StackTrace;

            ms = ms.Length > 1000 ? ms.Substring(0, 1000) : ms;
            st = st.Length > 1000 ? st.Substring(0, 1000) : st;

            var embed = new DiscordEmbedBuilder
            {
                Color       = new DiscordColor(0xFF0000),
                Title       = "An exception occured when executing a command",
                Description = string.Concat("`", e.Exception.GetType(), "` occured when executing `", e.Command.QualifiedName, "`."),
                Timestamp   = DateTime.UtcNow
            }.WithFooter(Discord.CurrentUser.AvatarUrl, Discord.CurrentUser.Username)
            .AddField("Message", ms, false)
            .AddField("Stack trace", $"```cs\n{st}\n```", false);

            await e.Context.Channel.SendMessageAsync("\u200b", embed : embed);
        }
Exemple #3
0
 private async Task OnCommandError(CommandErrorEventArgs e)
 {
     if (e.Exception is ChecksFailedException)
     {
         var channel = e.Context.Channel;
         var eEmbed  = new DiscordEmbedBuilder
         {
             Title = "You have insufficient permissions to execute this command!",
             Color = DiscordColor.Red
         };
         var rEmbed = new DiscordEmbedBuilder
         {
             Title = "You do not have the required role for this!",
             Color = DiscordColor.Red
         };
         var ElseEmbed = new DiscordEmbedBuilder
         {
             Title = "Something went wrong on our end, sorry for any inconvenience.",
             Color = DiscordColor.Red
         };
         var PermError = (ChecksFailedException)e.Exception;
         if (PermError.FailedChecks[0] is RequirePermissionsAttribute)
         {
             await channel.SendMessageAsync(embed : eEmbed).ConfigureAwait(false);
         }
         var properError = (ChecksFailedException)e.Exception;
         if (properError.FailedChecks[0] is RequireRolesAttribute)
         {
             await channel.SendMessageAsync(embed : rEmbed).ConfigureAwait(false);
         }
     }
 }
Exemple #4
0
        private async Task Commands_CommandErrored(CommandErrorEventArgs e)
        {
            // let's log the name of the guild that was just
            // sent to our client
            e.Context.Client.DebugLogger.LogMessage(LogLevel.Error, "ExampleBot", $"{e.Context.User.Username} tried executing '{e.Command?.QualifiedName ?? "<unknown command>"}' but it errored: {e.Exception.GetType()}: {e.Exception.Message ?? "<no message>"}", DateTime.Now);

            // let's check if the error is a result of lack
            // of required permissions
            if (e.Exception is ChecksFailedException ex)
            {
                // yes, the user lacks required permissions,
                // let them know

                var emoji = DiscordEmoji.FromName(e.Context.Client, ":no_entry:");

                // let's wrap the response into an embed
                var embed = new DiscordEmbed
                {
                    Title       = "Access denied",
                    Description = $"{emoji} You do not have the permissions required to execute this command.",
                    Color       = 0xFF0000 // red
                };
                await e.Context.RespondAsync("", embed : embed);
            }
        }
Exemple #5
0
        //Display errors that occur when a user tries to run a command
        //(In this case, we hide argcount, parsing and unknown command errors to reduce spam in servers with multiple bots)
        private void OnCommandError(object sender, CommandErrorEventArgs e)
        {
            string msg = e.Exception?.GetBaseException().Message;

            if (msg == null) //No exception - show a generic message
            {
                switch (e.ErrorType)
                {
                case CommandErrorType.Exception:
                    //msg = "Unknown error.";
                    break;

                case CommandErrorType.BadPermissions:
                    msg = "You do not have permission to run this command.";
                    break;

                case CommandErrorType.BadArgCount:
                    //msg = "You provided the incorrect number of arguments for this command.";
                    break;

                case CommandErrorType.InvalidInput:
                    //msg = "Unable to parse your command, please check your input.";
                    break;

                case CommandErrorType.UnknownCommand:
                    //msg = "Unknown command.";
                    break;
                }
            }
            if (msg != null)
            {
                _client.ReplyError(e, msg);
                _client.Log.Error("Command", msg);
            }
        }
Exemple #6
0
        private async System.Threading.Tasks.Task CommandFailed(CommandErrorEventArgs e)
        {
            if (e.Exception?.Message != null && e.Exception.Message.Contains("403"))
            {
                await e.Context.RespondAsync(
                    "**This command required me to have the `Administrator` permission in your discord server. Please allow me this permission and try the command again!**");

                return;
            }

            var exceptionHandled = await HandleException(e.Exception, e.Context);

            if (exceptionHandled)
            {
                return;
            }

            if (e.Exception is ChecksFailedException cfe)
            {
                foreach (var ex in cfe.FailedChecks)
                {
                    switch (ex)
                    {
                    case CooldownAttribute cooldown:
                        await e.Context.RespondAsync(
                            $"Cooldown: **{cooldown.GetRemainingCooldown(e.Context).Seconds}s**");

                        return;
                    }
                }
            }
        }
Exemple #7
0
        private async Task CommandErrored(CommandErrorEventArgs e)
        {
            var command = e.Command;
            var context = e.Context;
            var guild   = context.Guild;
            var channel = context.Channel;
            var user    = context.User;

            if (!channel.IsPrivate)
            {
                if (channel != null && user != null)
                {
                    await channel.DeleteMessageByIdAsync(context.Message.Id);

                    _logger.Error(e.Exception, $"The command '{command.Name}' has been errored by '{user.GetUsertag()}' in the channel '{channel.Name}' ({channel.Id}) on the guild '{guild.Name}' ({guild.Id}).");
                }
                else
                {
                    _logger.Error(e.Exception, $"The command '{command.Name}' has been errored by an unknown user in a deleted channel on a unknown guild.");
                }
            }
            else
            {
                _logger.Information($"The command '{command.Name}' has been errored by '{user.GetUsertag()}' ({user.Id}) in the direct message.");
            }
        }
Exemple #8
0
        private async Task Commands_CommandErrored(CommandErrorEventArgs e)
        {
            loadJSON();
            // let's log the error details
            e.Context.Client.DebugLogger.LogMessage(LogLevel.Error, "SWGOHBot", $"{e.Context.User.Username} tried executing '{e.Command?.QualifiedName ?? "<unknown command>"}' but it errored: {e.Exception.GetType()}: {e.Exception.Message ?? "<no message>"}", DateTime.Now);

            // let's check if the error is a result of lack of required permissions
            if (e.Exception is ChecksFailedException ex)
            {
                // yes, the user lacks required permissions,  let them know
                var emoji = DiscordEmoji.FromName(e.Context.Client, ":no_entry:");

                // let's wrap the response into an embed
                var embed = new DiscordEmbedBuilder
                {
                    Title       = "Access denied",
                    Description = $"{emoji} You do not have the permissions required to execute this command.",
                    Color       = new DiscordColor(0xFF0000) // red
                };
                await e.Context.RespondAsync("", embed : embed);
            }

            if (e.Exception is ArgumentException)
            {
                String s = "";

                if (!AllyCode.IsValid(Convert.ToUInt32(e.Exception.Data["allycode"])))
                {
                    s = $":scream:The ally code given is invalid, please try again with a valid ally code.";
                }
                else
                {
                }
                var emoji = DiscordEmoji.FromName(e.Context.Client, ":no_entry:");

                if (e.Exception.Data.Keys.Count > 0)
                {
                    for (int i = 0; i < e.Exception.Data.Keys.Count; i++)
                    {
                        if (e.Exception.Data[i] == null)
                        {
                            s += "I need a value for " + e.Exception.Data[i];
                        }
                    }
                }
                else
                {
                    //s = $":scream:You haven't told me anything. I need to know who I'm looking for and for whom\nTry {cfgjson.CommandPrefix}reqs <character> <ally code>";
                }
                // let's wrap the response into an embed
                var embed = new DiscordEmbedBuilder
                {
                    Title       = "Jar Jar",
                    Description = s,                         //$"{emoji} I need to know who you want me to look for. Example: thrawn",
                    Color       = new DiscordColor(0xFF0000) // red
                };
                await e.Context.RespondAsync("", embed : embed);
            }
        }
Exemple #9
0
        public async Task OnErrored(CommandsNextExtension cn, CommandErrorEventArgs ev)
        {
            await Task.Run(async() =>
            {
                switch (ev.Exception.Message)
                {
                case "Could not find a suitable overload for the command.":
                    await ev.Context.Channel.SendMessageAsync(
                        embed: new DiscordEmbedBuilder()
                        .WithTitle(":warning: Wrong arguments")
                        .WithDescription("Missing or invalids arguments")
                        .WithColor(DiscordColor.IndianRed)
                        .Build()
                        );
                    break;

                case "One or more pre-execution checks failed.":
                    await ev.Context.Channel.SendMessageAsync(
                        embed: new DiscordEmbedBuilder()
                        .WithTitle(":no_entry: Missing permissions")
                        .WithDescription($"You don't have enough permission to execute the command `{ev.Command.Name}`")
                        .WithColor(DiscordColor.IndianRed)
                        .Build()
                        );
                    break;

                case "Specified command was not found.":
                    await ev.Context.Channel.SendMessageAsync(
                        embed: new DiscordEmbedBuilder()
                        .WithTitle(":interrobang: Unknown command")
                        .WithDescription($"The specified command don't seems to exist")
                        .WithColor(DiscordColor.IndianRed)
                        .Build()
                        );
                    break;

                case "No matching subcommands were found, and this group is not executable.":
                    await ev.Context.Channel.SendMessageAsync(
                        embed: new DiscordEmbedBuilder()
                        .WithTitle(":interrobang: Unknown command")
                        .WithDescription($"The specified command don't seems to exist in this category")
                        .WithColor(DiscordColor.IndianRed)
                        .Build()
                        );
                    break;

                default:
                    await ev.Context.Channel.SendMessageAsync(
                        embed: new DiscordEmbedBuilder()
                        .WithTitle(":warning: An error has occured")
                        .WithFooter("If you think there is a problem please contact the bot owner: Lexa#3625", cn.Client.CurrentUser.AvatarUrl)
                        .WithDescription(ev.Exception.Message)
                        .WithColor(DiscordColor.IndianRed)
                        .Build()
                        );
                    break;
                }
            });
        }
Exemple #10
0
 private static Task Commands_CommandErrored(CommandErrorEventArgs e)
 {
     e.Context.Client.DebugLogger.LogMessage(DSharpPlus.LogLevel.Error,
                                             "Splash",
                                             $"Command error, {e.Exception.GetType()}: {e.Exception.Message}",
                                             DateTime.Now);
     return(Task.CompletedTask);
 }
Exemple #11
0
 private static async Task _cnext_CommandErrored(CommandErrorEventArgs e)
 {
     //await e.Context.Channel.SendMessageAsync(
     //    $"{e.Context.Message.Author.Mention}'s Command ```{Environment.NewLine}{e.Context.Message.Content}{Environment.NewLine}``` ERRORED SEE LOG");
     //await e.Context.Message.DeleteAsync();
     Console.WriteLine($"ERROR: {e.Command}, {e.Exception.Message}");
     //GameLog.Log($"[ERROR] {e.Command}, {e.Exception.Message}", "Commands");
 }
Exemple #12
0
 public Task itError(CommandErrorEventArgs oof)
 {
     if (oof.Exception.HResult != -2146233088)
     {
         oof.Context.RespondAsync(oof.Command.Description); //as i explained above
     }
     return(Task.CompletedTask);
 }
Exemple #13
0
        private async Task Commands_CommandErrored(CommandsNextExtension sender, CommandErrorEventArgs e)
        {
            switch (e.Exception)
            {
            case CommandNotFoundException:
            {
                await e.Context.RespondAsync("Tento příkaz neznám.");

                CommandContext?fakeContext = Commands.CreateFakeContext(e.Context.Member, e.Context.Channel,
                                                                        $"help", e.Context.Prefix,
                                                                        Commands.FindCommand($"help", out string args), args
                                                                        );
                await Commands.ExecuteCommandAsync(fakeContext);

                break;
            }

            case InvalidOperationException:
            case ArgumentException:
            {
                await e.Context.RespondAsync("Příkaz jsi zadal špatně.");

                CommandContext?fakeContext = Commands.CreateFakeContext(e.Context.Member, e.Context.Channel,
                                                                        $"help {e.Command?.QualifiedName}", e.Context.Prefix,
                                                                        Commands.FindCommand($"help {e.Command?.QualifiedName}", out string args), args
                                                                        );
                await Commands.ExecuteCommandAsync(fakeContext);

                break;
            }

            case ChecksFailedException:
            {
                DiscordEmoji emoji = DiscordEmoji.FromName(e.Context.Client, ":no_entry:");

                DiscordEmbedBuilder embed = new()
                {
                    Title       = "Přístup zakázán",
                    Description =
                        $"{emoji} Na vykonání příkazu nemáte dostatečná práva. Pokud si myslíte že ano, kontaktujte svého MODa.",
                    Color = new DiscordColor(0xFF0000)     // red
                };
                await e.Context.RespondAsync("", embed : embed);

                break;
            }

            default:
                await e.Context.RespondAsync("Něco se pokazilo. Hups. :scream_cat:");

                e.Context.Client.Logger.LogError(e.Exception,
                                                 "{Username} tried executing '{CommandName}' but it errored: {ExceptionType}: {ExceptionMessage}",
                                                 e.Context.User.Username,
                                                 e.Command?.QualifiedName ?? "<unknown command>", e.Exception.GetType(),
                                                 e.Exception.Message);
                break;
            }
        }
 private Task CommandsNext_CommandErrored(CommandErrorEventArgs e)
 {
     this.Logger.LogError(e.Exception, "User '{0}' failed to execute '{1}' in '{2}' ({3}).",
                          e.Context.User,
                          e.Command?.QualifiedName ?? "<none>",
                          e.Context.Channel.Name,
                          e.Context.Channel.Id);
     return(Task.CompletedTask);
 }
Exemple #15
0
    /// <summary>
    /// Triggered whenever a command throws an exception during execution.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="e">Arguments</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    private async Task OnCommandErrored(CommandsNextExtension sender, CommandErrorEventArgs e)
    {
        if (e.Exception is CommandNotFoundException)
        {
            var serviceProvider = GlobalServiceProvider.Current.GetServiceProvider();
            await using (serviceProvider.ConfigureAwait(false))
            {
                var client = serviceProvider.GetService <IHttpClientFactory>().CreateClient();

                using (var response = await client.GetAsync("https://g.tenor.com/v1/search?q=what&key=RXM3VE2UGRU9&limit=100&contentfilter=high&ar_range=all")
                                      .ConfigureAwait(false))
                {
                    var jsonResult = await response.Content.ReadAsStringAsync()
                                     .ConfigureAwait(false);

                    var searchResult = JsonConvert.DeserializeObject <SearchResultRoot>(jsonResult);

                    await e.Context
                    .Message
                    .RespondAsync(searchResult.Results[_rnd.Next(0, searchResult.Results.Count - 1)]
                                  .ItemUrl)
                    .ConfigureAwait(false);
                }
            }
        }
        else if (e.Exception is TimeoutException)
        {
        }
        else if (e.Exception is ArgumentException ||
                 e.Exception is InvalidOperationException)
        {
            var cmd = e.Context.CommandsNext.FindCommand("help " + e.Command.QualifiedName, out var customArgs);

            cmd ??= e.Context.CommandsNext.FindCommand("help", out customArgs);

            if (e.Context.Channel.IsPrivate)
            {
                if (e.Context.Client.PrivateChannels.ContainsKey(e.Context.Channel.Id) == false)
                {
                    if (e.Context.Member != null)
                    {
                        await e.Context
                        .Member
                        .CreateDmChannelAsync()
                        .ConfigureAwait(false);
                    }
                }
            }

            var fakeContext = e.Context.CommandsNext.CreateFakeContext(e.Context.Member ?? e.Context.User, e.Context.Channel, "help " + e.Command.QualifiedName, e.Context.Prefix, cmd, customArgs);

            await e.Context
            .CommandsNext
            .ExecuteCommandAsync(fakeContext)
            .ConfigureAwait(false);
        }
    }
Exemple #16
0
        private Task LogErroredCommand(CommandErrorEventArgs e)
        {
            _logger.LogError("An exception was thrown while executing command '{0}' for user '{1}'.\r\n{2}",
                             e.Command.Name,
                             e.Context.User.ToString(),
                             e.Exception.StackTrace);

            return(Task.CompletedTask);
        }
Exemple #17
0
        private Task OnCommandError(CommandErrorEventArgs e)
        {
            if (!(e.Exception !is CommandNotFoundException))
            {
                e.Context.Channel.SendMessageAsync(e.Exception.Message);
            }

            return(Task.CompletedTask);
        }
 /// <summary>
 /// 编辑器中执行命令时的错误处理
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void myEditControl_CommandError(object sender, CommandErrorEventArgs args)
 {
     MessageBox.Show(
         this,
         args.CommandName + "\r\n" + args.Exception.ToString(),
         this.Text,
         MessageBoxButtons.OK,
         MessageBoxIcon.Exclamation);
 }
        private async Task Commands_CommandErrored(CommandErrorEventArgs e)
        {
            loadJSON();
            // let's log the error details
            e.Context.Client.DebugLogger.LogMessage(LogLevel.Error, "SWGOHBot", $"{e.Context.User.Username} tried executing '{e.Command?.QualifiedName ?? "<unknown command>"}' but it errored: {e.Exception.GetType()}: {e.Exception.Message ?? "<no message>"}", DateTime.Now);

            // let's check if the error is a result of lack of required permissions
            if (e.Exception is ChecksFailedException ex)
            {
                // yes, the user lacks required permissions,  let them know
                var emoji = DiscordEmoji.FromName(e.Context.Client, ":no_entry:");

                // let's wrap the response into an embed
                var embed = new DiscordEmbedBuilder
                {
                    Title       = "Access denied",
                    Description = $"{emoji} You do not have the permissions required to execute this command.",
                    Color       = new DiscordColor(0xFF0000) // red
                };
                await e.Context.RespondAsync("", embed : embed);
            }
            if (e.Exception is NotFoundException nfe)
            {
                String s = $":scream:The command must be ran with either 2 arguements or a Discord user.";
                // let's wrap the response into an embed
                var embed = new DiscordEmbedBuilder
                {
                    Title       = "Uh Oh! Looks like there was a problem!",
                    Description = s,                         //$"{emoji} I need to know who you want me to look for. Example: thrawn",
                    Color       = new DiscordColor(0xFF0000) // red
                };
                await e.Context.RespondAsync("", embed : embed);
            }

            if (e.Exception is ArgumentException)
            {
                String s = "";

                if (!AllyCode.IsValid(Convert.ToUInt32(e.Exception.Data["allycode"])))
                {
                    s = $":scream:The command must be ran with either 2 arguements or a Discord user.";
                }
                else
                {
                }
                var emoji = DiscordEmoji.FromName(e.Context.Client, ":no_entry:");

                // let's wrap the response into an embed
                var embed = new DiscordEmbedBuilder
                {
                    Title       = "Uh Oh! Looks like there was a problem!",
                    Description = s,                         //$"{emoji} I need to know who you want me to look for. Example: thrawn",
                    Color       = new DiscordColor(0xFF0000) // red
                };
                await e.Context.RespondAsync("", embed : embed);
            }
        }
Exemple #20
0
 void copy_OnCommandError(object sender, CommandErrorEventArgs e)
 {
     Dispatcher.BeginInvoke((Action)(() =>
     {
         MessageBox.Show(e.Error);
         OptionsGrid.IsEnabled = true;
         ProgressGrid.IsEnabled = false;
     }));
 }
Exemple #21
0
        public Task OnCommandError(CommandsNextExtension commandSystem, CommandErrorEventArgs e)
        {
            switch (e.Exception)
            {
            case CommandNotFoundException ex:
                return(Task.CompletedTask);

            case ArgumentException ex:
            {
                if (!ConfigParser.IsCommandChannel(e.Context.Channel.Id))
                {
                    return(Task.CompletedTask);
                }
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Invalid arguments."
                };
                e.Context?.Channel?.SendMessageAsync(error);
                return(Task.CompletedTask);
            }

            case ChecksFailedException ex:
            {
                if (!ConfigParser.IsCommandChannel(e.Context.Channel.Id))
                {
                    return(Task.CompletedTask);
                }
                foreach (CheckBaseAttribute attr in ex.FailedChecks)
                {
                    DiscordEmbed error = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Red,
                        Description = this.ParseFailedCheck(attr)
                    };
                    e.Context?.Channel?.SendMessageAsync(error);
                }
                return(Task.CompletedTask);
            }

            default:
            {
                Logger.Error($"Exception occured: {e.Exception.GetType()}: {e.Exception}", LogID.Discord);
                if (!ConfigParser.IsCommandChannel(e.Context.Channel.Id))
                {
                    return(Task.CompletedTask);
                }
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Internal error occured, please report this to the developer."
                };
                e.Context?.Channel?.SendMessageAsync(error);
                return(Task.CompletedTask);
            }
            }
        }
Exemple #22
0
        private static async Task CommandErroredAsync(CommandErrorEventArgs e)
        {
            Log.Error(e.Exception,
                      $"Command {e.Command.Name} errored in Channel {e.Context.Channel.Name} in Guild {e.Context.Guild.Name} written by {e.Context.Message.Author}.");

            if (e.Exception is InvalidBeatmapException)
            {
                await e.Context.RespondAsync("It's an invalid beatmap.");
            }
        }
Exemple #23
0
        /// <summary>
        /// Отправляем в консоль сообщения об ошибках при выполнении команды.
        /// </summary>
        private Task CommandsOnCommandErrored(CommandErrorEventArgs e)
        {
            e.Context.Client.DebugLogger.LogMessage(LogLevel.Warning, "SoT", $"{e.Command.Name} errored with {e.Exception.Message}!",
                                                    DateTime.Now);

            e.Context.Client.DebugLogger.LogMessage(LogLevel.Warning, "SoT", $"{e.Exception.StackTrace}!",
                                                    DateTime.Now);

            return(Task.CompletedTask);
        }
Exemple #24
0
        public static Task CommandErrorEventHandlerAsync(TheGodfatherBot bot, CommandErrorEventArgs e)
        {
            if (e.Exception is null)
            {
                return(Task.CompletedTask);
            }

            Exception ex = e.Exception;

            while (ex is AggregateException or TargetInvocationException && ex.InnerException is { })
        private async static Task PrintError(CommandErrorEventArgs e)
        {
            if (e.Exception is CommandNotFoundException)
            {
                return;
            }
            await e.Context.Channel.SendMessageAsync($"An error occured: {e.Exception.Message}");

            Console.Error.WriteLine(e.Exception);
        }
Exemple #26
0
        private Task Commands_CommandErrored(CommandErrorEventArgs e)
        {
            if (!(e.Exception is CommandNotFoundException) &&
                !(e.Exception is ChecksFailedException))
            {
                e.Context.Client.DebugLogger
                .LogMessage(LogLevel.Error, "FloppyEars", $"Exception: {e.Exception.GetType()}: {e.Exception.Message}", DateTime.Now);
            }

            return(Task.CompletedTask);
        }
Exemple #27
0
        private Task OnCommandError(CommandErrorEventArgs e)
        {
            if (e?.Command != null)
            {
                Log.Error(e.Exception, "Command {command} failed executing for user {userMention}", e.Command.Name,
                          e.Context.User.Mention);
                e.Context.Message.AddError();
            }

            return(Task.CompletedTask);
        }
Exemple #28
0
        public async Task Client_CommandErrored(CommandsNextExtension sender, CommandErrorEventArgs e)
        {
            sender.Client.Logger.LogWarning(DiscordBot.Event_ClientLogger, $"Command {e.Command.Name} errored when executed by {e.Context.User.Username} on {e.Context.Guild.Name}");
            sender.Client.Logger.LogDebug(DiscordBot.Event_ClientLogger, e.Exception, $"Exception Information for Command Error");

#if DEBUG
            await e.Context.RespondAsync($"The following error occoured: {e.Exception.Message} ```{e.Exception.StackTrace}```");
#else
            await e.Context.RespondAsync($"The following error occoured: {e.Exception.Message} ```{e.Exception.StackTrace}```");
#endif
        }
        // loosely based on kekbotsharp
        // does shit
        private static async Task HandleError(CommandErrorEventArgs errorArgs)
        {
            var error = errorArgs.Exception;
            var ctx   = errorArgs.Context;

            if (error is CommandCancelledException)
            {
                return;
            }
            await PrintError(errorArgs);
        }
Exemple #30
0
 private static async Task Commands_CommandErrored(CommandErrorEventArgs e)
 {
     if (e.Exception is OutputException)
     {
         await e.Context.RespondAsync(e.Exception.Message);
     }
     else
     {
         e.Context.Client.DebugLogger.LogMessage(LogLevel.Error, "Jigglypuff", e.Exception.ToString(), DateTime.Now);
     }
 }
Exemple #31
0
 public async void HandleError(object sender, CommandErrorEventArgs e) {
     if (e.ErrorType == CommandErrorType.Exception)
     {
         await e.Channel.SendMessage("I don't know what you just did but something just went wrong. ");
         Console.WriteLine(e.Exception.ToString());
     }
     if (e.ErrorType == CommandErrorType.BadPermissions)
     {
         await e.Channel.SendMessage("You don't have permission to do that loser.");
     }
     if (e.ErrorType == CommandErrorType.UnknownCommand)
     {
         if (e.Message.IsMentioningMe()) { return; }
         //await e.Channel.SendMessage("I don't know what that is, It probably doesn't exist. Wow you really messed up.");
     }
 }
Exemple #32
0
 //Log any messages. Copied from DiscordBot (https://github.com/RogueException/DiscordBot)
 //Display errors that occur when a user tries to run a command
 //(In this case, we hide argcount, parsing and unknown command errors to reduce spam in servers with multiple bots)
 private void OnCommandError(object sender, CommandErrorEventArgs e)
 {
     string msg = e.Exception?.GetBaseException().Message;
     if (msg == null) //No exception - show a generic message
     {
         switch (e.ErrorType)
         {
             case CommandErrorType.Exception:
                 //msg = "Unknown error.";
                 break;
             case CommandErrorType.BadPermissions:
                 msg = "You do not have permission to run this command.";
                 break;
             case CommandErrorType.BadArgCount:
                 //msg = "You provided the incorrect number of arguments for this command.";
                 break;
             case CommandErrorType.InvalidInput:
                 //msg = "Unable to parse your command, please check your input.";
                 break;
             case CommandErrorType.UnknownCommand:
                 //msg = "Unknown command.";
                 break;
         }
     }
     if (msg != null)
     {
         Client.Log.Error("Command", msg);
     }
 }
Exemple #33
0
 private static void CommandError(object sender, CommandErrorEventArgs e)
 {
     string msg = e.Exception?.GetBaseException().Message;
     if (msg == null) //No mxception - show a generic message
     {
         switch (e.ErrorType)
         {
             case CommandErrorType.Exception:
                 msg = "Unknown Error";
                 break;
             case CommandErrorType.BadPermissions:
                 msg = "You do not have permission to run this command.";
                 break;
             case CommandErrorType.BadArgCount:
                 msg = "You provided the incorrect number of arguments for this command.";
                 break;
             case CommandErrorType.InvalidInput:
                 msg = "Unable to parse your command, please check your input.";
                 break;
             case CommandErrorType.UnknownCommand:
                 /* This command just wasn't for Neko, don't interrupt!
                 msg = "Unknown command.";
                 break;
                 */
                 return;
         }
     }
     if (msg != null)
     {
         client.SendMessage(e.Channel, "Command Error: " + msg);
         //Console.WriteLine(msg);
     }
 }