【发布时间】:2021-06-24 02:11:37
【问题描述】:
我正在学习如何使用 discord.py 创建一个不和谐机器人,但每当我弄乱我的代码时,有时我会收到“TypeError”错误。
例如
@bot.command()
async def compress(ctx):
directory = '/pictures/'
picture = '83680009_p0.png'
path = directory+picture
img = Image.open(path)
img.save(path, optimize=True, quality = 85)
img.save()
该代码中有一个错误,错误在directory = '/pictures/' 行中。 'pictures/' 之前不应该有反斜杠。所以,当我尝试运行 compress 命令时,我得到了错误
TypeError: on_command_error() missing 1 required positional argument: 'error'
有没有办法处理错误并在发生此错误时向机器人发送消息?谢谢。顺便说一句,这是我第一次提出问题,所以如果我遗漏了什么,请告诉我。
【问题讨论】:
标签: error-handling discord.py typeerror