我正在尝试使用以下代码在不和谐的python机器人中创建错误消息:
@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')
但我在控制台中收到此错误:
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'
我不明白为什么会这样。
如果需要,清除命令:
@client.command
@commands.has_permissions(manage_messages=True)
async def purge(ctx, amount : int):
await ctx.channel.purge(limit=amount)
await ctx.send('Done!')
尝试这个:
according to: I have a error in discord.py (purge command)
You're missing the parentheses in your
@client.command
decorator.Try changing it to
@client.command()
and you should be good to go.参考:
commands.command()