Python not having function overloading

Made separate async defs for on_command_error
pull/2/head
sgoudham 4 years ago
parent 6fd7e1c8cb
commit 19b37678c0

@ -292,20 +292,30 @@ async def remind_me(ctx, time=None, *, text):
await author.send(text) await author.send(text)
# Bot Event for handling cooldown error/permission errors # Bot Event for handling missing argument error
@client.event @client.event
async def on_command_error(ctx, error): async def on_command_error(ctx, args2):
if isinstance(error, commands.CommandOnCooldown): if isinstance(args2, commands.MissingRequiredArgument):
await on_command_missing_user(ctx)
elif isinstance(args2, commands.CommandOnCooldown):
await on_command_cooldown(ctx, args2)
elif isinstance(args2, commands.CheckFailure):
await on_command_permission(ctx)
# Async def for handling cooldown error/permission errors
async def on_command_cooldown(ctx, error):
# Send an error message to the user telling them that the command is on cooldown # Send an error message to the user telling them that the command is on cooldown
message = await ctx.send(f'That command is on cooldown. Try again in {error.retry_after:,.2f} seconds.') message = await ctx.send(f'That command is on cooldown. Try again in {error.retry_after:,.2f} seconds.')
# Let the user read the message for 2.5 seconds # Let the Auser read the message for 2.5 seconds
await asyncio.sleep(2.5) await asyncio.sleep(2.5)
# Delete the message # Delete the message
await message.delete() await message.delete()
# Bot Event for handling permission errors
if isinstance(error, commands.CheckFailure): # Async def for handling permission errors
async def on_command_permission(ctx):
# Send an error message to the user saying that they don't have permission to use this command # Send an error message to the user saying that they don't have permission to use this command
message = await ctx.send("Uh oh! You don't have permission to use this command!") message = await ctx.send("Uh oh! You don't have permission to use this command!")
@ -315,10 +325,7 @@ async def on_command_error(ctx, error):
await message.delete() await message.delete()
# Bot Event for handling missing argument error async def on_command_missing_user(ctx):
@client.event
async def on_command_error(ctx, target: discord.Member):
if isinstance(target, commands.MissingRequiredArgument):
# Send an error message to the user saying that an argument is missing # Send an error message to the user saying that an argument is missing
message = await ctx.send("Uh oh! Couldn't find anyone to mention! Try again!") message = await ctx.send("Uh oh! Couldn't find anyone to mention! Try again!")

Loading…
Cancel
Save