Send a message if Wait_For_Message timeout is reached Discord Py

不问归期 提交于 2019-12-24 08:08:39

问题


I'm trying to send a message if the timeout is reached for client.wait_for_message. In this case it's 30 seconds. I used TimeoutError but it doesn't throw any errors or work.

 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))

回答1:


Sorry after researching a bit i came up with this solution:

     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))


来源:https://stackoverflow.com/questions/52360859/send-a-message-if-wait-for-message-timeout-is-reached-discord-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!