Im trying to create error messages in my discord python bot with this code:
@purge.error
async def clear_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send('Please specify the amount of messages you want to clear. Usage: //clear <number>')
if isinstance(error, commands.MissingPermissions):
await ctx.send('You do not have manage_messages permssion')
but im getting this error in the console:
Traceback (most recent call last):
File "c:/projects/bad bot/bot.py", line 132, in <module>
@purge.error
AttributeError: 'function' object has no attribute 'error'
and I don't understand why is it happening.
If needed the purge command:
@client.command
@commands.has_permissions(manage_messages=True)
async def purge(ctx, amount : int):
await ctx.channel.purge(limit=amount)
await ctx.send('Done!')
You're missing the parentheses in your @client.command
decorator.
Try changing it to @client.command()
and you should be good to go.
Reference:
commands.command()
You gotta do it like this
@client.event
async def on_command_error(ctx, error):
pass
@client.command()
@commands.has_permissions(manage_messages=True)
async def purge(ctx, amount : int):
await ctx.channel.purge(limit=amount)
await ctx.send('Done!')
@purge.error
async def clear_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send('Please specify the amount of messages you want to clear. Usage: //clear <number>')
if isinstance(error, commands.MissingPermissions):
await ctx.send('**You do not have manage_messages permssion!**')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With