🥅 - Catching command errors better than ever

This commit is contained in:
Florian Sylvain
2021-04-12 17:27:41 +02:00
parent 4afa590378
commit 4e9ffd2954
2 changed files with 14 additions and 3 deletions
+6
View File
@@ -0,0 +1,6 @@
from discord.ext import commands
errors = {commands.MissingRequiredArgument:"A required argument is missing !",
commands.TooManyArguments:"You entered too many arguments !",
commands.NotOwner:"Only the owner of the bot can use this command... *Where did you get it ?*",
commands.BotMissingPermissions:"I'm missing some permissions to execute this command !"}
+8 -3
View File
@@ -5,7 +5,7 @@ import discord
from discord.ext import commands
from miscellaneous import spellchecker
from private import TOKEN_BOT
from errors import errors
print('Loading started')
@@ -39,9 +39,14 @@ async def on_command_error(ctx, error):
' \'' + str(error) + '\' from ' + str(ctx.author) + ' on ' +
(ctx.message.guild.name if ctx.message.guild is not None else 'DMs') + '.')
if isinstance(error, commands.CommandNotFound):
await ctx.send(spellchecker(str(ctx.message.content)[1:], commandlist))
msg = spellchecker(str(ctx.message.content)[1:], commandlist)
else:
await ctx.send(error)
try:
msg = errors[type(error)] + "\nPlease follow this pattern :\n``" + \
"$" + ctx.command.name + " " + ctx.command.signature + "``"
except KeyError:
msg = "Something really bad happened (" + str(error) + ")."
await ctx.send(msg)
def init():