🛑 Better exception handling

This commit is contained in:
NikolajDanger
2021-03-27 15:31:08 +01:00
parent 81b4eec190
commit 552f00ff32
2 changed files with 10 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import discord, os, finnhub, platform, asyncio
import discord, os, finnhub, platform, asyncio, traceback
from discord.ext import commands
from pymongo import MongoClient
@ -86,7 +86,14 @@ async def on_command_error(ctx, error):
logThis(f"{error}",str(ctx.message.channel.id))
await ctx.send("Missing command parameters (error code 002). Try using `!help [command]` to find out how to use the command.")
else:
logThis(f"Something went wrong, {error}, ({type(error)})",str(ctx.message.channel.id))
exception = traceback.format_exception(type(error), error, error.__traceback__)
stopAt = "\nThe above exception was the direct cause of the following exception:\n\n"
if stopAt in exception:
index = exception.index(stopAt)
exception = exception[:index]
exceptionString = "".join(exception)
logThis(f"exception in command !{ctx.command}, {exceptionString}",str(ctx.message.channel.id))
await ctx.send("Something went wrong (error code 000)")
#Loads cogs