🛑 Better exception handling
This commit is contained in:
11
Gwendolyn.py
11
Gwendolyn.py
@ -1,4 +1,4 @@
|
|||||||
import discord, os, finnhub, platform, asyncio
|
import discord, os, finnhub, platform, asyncio, traceback
|
||||||
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from pymongo import MongoClient
|
from pymongo import MongoClient
|
||||||
@ -86,7 +86,14 @@ async def on_command_error(ctx, error):
|
|||||||
logThis(f"{error}",str(ctx.message.channel.id))
|
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.")
|
await ctx.send("Missing command parameters (error code 002). Try using `!help [command]` to find out how to use the command.")
|
||||||
else:
|
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)")
|
await ctx.send("Something went wrong (error code 000)")
|
||||||
|
|
||||||
#Loads cogs
|
#Loads cogs
|
||||||
|
@ -45,6 +45,7 @@ class MiscCog(commands.Cog):
|
|||||||
|
|
||||||
self.client.funcs.stopServer()
|
self.client.funcs.stopServer()
|
||||||
|
|
||||||
|
logThis("Logging out.")
|
||||||
await self.client.logout()
|
await self.client.logout()
|
||||||
else:
|
else:
|
||||||
logThis(f"{ctx.message.author.display_name} tried to stop me! (error code 201)",str(ctx.message.channel.id))
|
logThis(f"{ctx.message.author.display_name} tried to stop me! (error code 201)",str(ctx.message.channel.id))
|
||||||
|
Reference in New Issue
Block a user