python - 如果达到 Wait_For_Message 超时则发送消息 Discord Py

标签 python python-3.x discord 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))

关于python - 如果达到 Wait_For_Message 超时则发送消息 Discord Py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52360859/

相关文章:

typescript - Discord.js 指南 : Property 'commands' does not exist on type 'Client<boolean>' in Typescript

c# - 为绕过 token 触发 hCaptcha 回调函数

javascript - 用户名和参数连接?\\Discord.js

python - 如何计算numpy中的连续数字

python-3.x - 在 Tensorflow 2.1.0 中强制急切执行

python - 如何在 Python Tkinter 中为 Frame 放置边框

python - Crypto.Signature.PKCS1_v1_5 和 Crypto.Signature.pkcs1_15 有什么区别?

python - 按与 Django User 的 ManyToMany 关系过滤模型

python - 将字符串解析为日期时间,同时在 pandas 中考虑 AM/PM

python - 如何加速找到两篇维基百科文章之间最短路径的程序