From 7d21850c3adf433b3235dbdd1265cf5ad4dd720d Mon Sep 17 00:00:00 2001 From: sgoudham Date: Sun, 19 Jul 2020 04:56:00 +0100 Subject: [PATCH] Error handling for arguments that don't make sense --- main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main.py b/main.py index ef595188..03610d04 100644 --- a/main.py +++ b/main.py @@ -200,6 +200,20 @@ async def on_command_error(ctx, args2): # if the user tries to access a command that isn't available elif isinstance(args2, commands.CommandNotFound): await on_command_not_found(ctx) + # if the user provides an argument that isn't recognised + elif isinstance(args2, commands.BadArgument): + await on_command_bad_argument(ctx) + + +# Async def for handling command not found error +async def on_command_bad_argument(ctx): + # Send an error message to the user telling them that the command doesn't exist + message = await ctx.send(f'**I could not find that member!**') + + # Let the User read the message for 5 seconds + await asyncio.sleep(5) + # Delete the message + await message.delete() # Async def for handling command not found error