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

问题描述 投票:1回答:1

如果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))
python python-3.x discord discord.py
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))
© www.soinside.com 2019 - 2024. All rights reserved.