python - 如果达到 Wait_For_Message 超时,则发送消息 Discord Py
问题描述
如果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))
解决方案
抱歉,经过一番研究后,我想出了这个解决方案:
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))
推荐阅读
- c# - .net core IActionResult 返回基类而不是派生类
- javascript - 如何将参数从 javascript 函数传递到另一个函数而不调用它?
- python-3.x - Python - Telnet 或 SSH 多个设备
- c++ - 避免堆栈溢出 C++
- mysql - 有没有办法使用logstash加入两个不同数据源(即Mysql和Postgres SQL)的数据库并将其索引到弹性搜索?
- java - 如何在 SpringBoot 中使用列表参数?
- python - 在 seaborn 中使用 sns.relplot.set 控制美学
- angular - 使用 fakeAsync 区域时如何为 ag-Grid 编写 Angular 测试?
- go - 服务器是否需要是指针
- postgresql - Postgres - 读取日期之前或之后的日期索引 (<, <=, >, >=)