📝 Better functioning error handling
This commit is contained in:
@ -4,6 +4,7 @@ from discord.ext import commands
|
|||||||
class EventCog(commands.Cog):
|
class EventCog(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
self.bot.on_error = self.on_error
|
||||||
|
|
||||||
# Syncs commands, sets the game, and logs when the bot logs in
|
# Syncs commands, sets the game, and logs when the bot logs in
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
@ -20,9 +21,8 @@ class EventCog(commands.Cog):
|
|||||||
async def on_slash_command_error(self, ctx, error):
|
async def on_slash_command_error(self, ctx, error):
|
||||||
await self.bot.errorHandler.on_slash_command_error(ctx, error)
|
await self.bot.errorHandler.on_slash_command_error(ctx, error)
|
||||||
|
|
||||||
# Logs if an error occurs
|
# Logs if on error occurs
|
||||||
@commands.Cog.listener()
|
async def on_error(self, method, *args, **kwargs):
|
||||||
async def on_error(self, method):
|
|
||||||
await self.bot.errorHandler.on_error(method)
|
await self.bot.errorHandler.on_error(method)
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import discord, traceback
|
import discord, traceback, discord_slash
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
class EventHandler():
|
class EventHandler():
|
||||||
@ -28,9 +28,11 @@ class ErrorHandler():
|
|||||||
async def on_slash_command_error(self, ctx, error):
|
async def on_slash_command_error(self, ctx, error):
|
||||||
if isinstance(error, commands.CommandNotFound):
|
if isinstance(error, commands.CommandNotFound):
|
||||||
await ctx.send("That's not a command (error code 001)")
|
await ctx.send("That's not a command (error code 001)")
|
||||||
elif isinstance(error,commands.errors.MissingRequiredArgument):
|
elif isinstance(error, commands.errors.MissingRequiredArgument):
|
||||||
self.bot.log(f"{error}",str(ctx.channel_id))
|
self.bot.log(f"{error}",str(ctx.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.")
|
||||||
|
elif isinstance(error, discord_slash.error.AlreadyResponded):
|
||||||
|
self.bot.log("Defer failed")
|
||||||
else:
|
else:
|
||||||
exception = traceback.format_exception(type(error), error, error.__traceback__)
|
exception = traceback.format_exception(type(error), error, error.__traceback__)
|
||||||
stopAt = "\nThe above exception was the direct cause of the following exception:\n\n"
|
stopAt = "\nThe above exception was the direct cause of the following exception:\n\n"
|
||||||
@ -53,4 +55,4 @@ class ErrorHandler():
|
|||||||
exception = exception[:index]
|
exception = exception[:index]
|
||||||
|
|
||||||
exceptionString = "".join(exception)
|
exceptionString = "".join(exception)
|
||||||
self.bot.log([f"exception in /{method}", f"{exceptionString}"], level = 40)
|
self.bot.log([f"exception in {method}", f"{exceptionString}"], level = 40)
|
Reference in New Issue
Block a user