From e5e3168130d9c3707c8922ed3cab6e9310cca563 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Sun, 19 Jul 2020 04:34:49 +0100 Subject: [PATCH] Error handling for commands not found --- main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main.py b/main.py index 6838f885..54731f1f 100644 --- a/main.py +++ b/main.py @@ -197,6 +197,20 @@ async def on_command_error(ctx, args2): # if the user does not the correct permissions to call a command elif isinstance(args2, commands.CheckFailure): await on_command_permission(ctx) + # if the user tries to access a command that isn't available + elif isinstance(args2, commands.CommandNotFound): + await on_command_not_found(ctx) + + +# Async def for handling cooldown error/permission errors +async def on_command_not_found(ctx): + # Send an error message to the user telling them that the command is on cooldown + message = await ctx.send(f'**Command Not Found! Please use `{ctx.prefix}help` to see all commands**') + + # Let the User read the message for 2.5 seconds + await asyncio.sleep(2.5) + # Delete the message + await message.delete() # Async def for handling cooldown error/permission errors