【发布时间】:2021-11-28 20:25:56
【问题描述】:
这是该错误的代码行:
if msg.startswith("!del"):
encouragements = []
if "encouragements" in db.keys():
index = int(msg.split("!del",1)[1])
delete_encouragement(index)
encouragements = db["encouragements"]
await message.channel.send(encouragements)
这是我不断收到的错误:
Ignoring exception in on_message
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 69, in on_message
index = int(msg.split("!del", 1)[1])
IndexError: list index out of range
每次我尝试运行 !del 命令时都会收到错误消息。
【问题讨论】:
-
您能否修复代码示例的缩进以完全匹配您正在使用的代码?
标签: python python-3.x discord.py bots