如果client.wait_for_message超时,我正在尝试发送消息。在这种情况下为30秒。我使用了TimeoutError,但它不会引发任何错误或无法正常工作。
try:
msg = await client.wait_for_message(timeout= 30, author=message.author, check=check)
if msg:
await client.send_message(message.channel, "Nice job! {} solved the scramble! The word was {}!".format(message.author.mention, word))
except TimeoutError:
await client.send_message(message.channel, "Oops! Nobody solved it. The word was {}!".format(word))
答案 0 :(得分:3)
import asyncio
try:
msg = await client.wait_for_message(timeout= 30, author=message.author, check=check)
if msg:
await client.send_message(message.channel, "message")
except asyncio.TimeoutError:
await client.send_message(message.channel, "message")
你的缩进是错误的,你的声明也是 应该是 asyncio.TimeoutError
抱歉回复了 2 年的帖子
答案 1 :(得分:1)
很抱歉,经过研究,我想出了以下解决方案:
msg = await client.wait_for_message(timeout= 30, author=message.author, check=check)
if msg:
await client.send_message(message.channel, "Nice job! {} solved the scramble! The word was {}!".format(message.author.mention, word))
elif msg is None:
await client.send_message(message.channel, "Oops! Nobody solved it. The word was {}!".format(word))