-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror_handler.py
More file actions
48 lines (35 loc) · 1.92 KB
/
error_handler.py
File metadata and controls
48 lines (35 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import discord
import traceback
import sys
from discord.ext import commands
class CommandErrorHandler(commands.Cog):
def __init__(self, bot):
self.bot=bot
@commands.Cog.listener()
async def on_command_error(self, context, error):
#Activador cuando se registra un error al trabajar con comandos
if hasattr(context.command,'on_error'):
return
cog=context.cog
if cog:
if cog._get_overridden_method(cog.cog_command_error) is not None:
return
error=getattr(error, 'original', error)
if isinstance(error, commands.CommandNotFound):
await context.message.channel.send('Ese comando no está registrado, usa el comando --help')
if isinstance(error, commands.DisabledCommand):
await context.message.channel.send('Este comando fue deshabilitado')
if isinstance(error, commands.MissingRequiredArgument):
await context.message.channel.send('Se espera un argumento, la sintaxis del comando se encuentra en --help')
if isinstance(error, commands.BadArgument):
await context.message.channel.send('El argumento no tiene el formato esperado, la sintaxis del comando se encuentra en --help')
if isinstance(error, commands.BotMissingPermissions):
await context.message.channel.send('El bot no cuenta con los permisos para realizar la acción')
if isinstance(error, commands.BotMissingRole):
await context.message.channel.send('El bot no cuenta con el rol')
if isinstance(error, commands.CommandRegistrationError):
await context.message.channel.send('Ya existe un comando con ese nombre')
if isinstance(error, commands.MemberNotFound):
await context.message.channel.send('No se encontró al usuario')
def setup(bot):
bot.add_cog(CommandErrorHandler(bot))