不一致索引超出范围消息



我想这样做,如果分割变量使错误列表索引超出范围,它将等待一条消息,说用户没有证明所需的输入。这是我想象中的样子:当我说test时,它会等待消息'Error'

if message.content.startswith('test'):
splitted = message.content.split(' ')[1]
await message.channel.send(splitted)

我建议使用try/except:

if message.content.startswith('test'):
try:
splitted = message.content.split(' ')[1]
await message.channel.send(splitted)
except IndexError:
# Await here for your error

相关内容

最新更新