【问题标题】:Send a message if Wait_For_Message timeout is reached Discord Py如果达到 Wait_For_Message 超时,则发送消息 Discord Py
【发布时间】:2019-02-20 23:19:49
【问题描述】:

如果 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】:

    抱歉,经过一番研究,我想出了这个解决方案:

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

    【讨论】:

      【解决方案2】:
      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")
      

      您的缩进是错误的,并且您的语句 for except 也是如此 应该是 asyncio.TimeoutError

      抱歉回复了 2 年的帖子

      【讨论】:

      • 抱歉,但我看不出您的答案与旧的和接受的答案有何不同。如果您认为缩进是错误的,您可以edit旧答案。我认为这会更好,而不是复制和超越旧的。
      • 抱歉造成误会。但我建议使用@hardestchat 答案正下方的edit 链接。您所做的是复制过去并创建一个与旧答案几乎相同的新答案。
      • 哦,对不起,我对堆栈溢出还很陌生
      • 没关系。我只是回应向您解释这一点。不要害怕,错误可能会发生。很高兴您参与其中,欢迎您加入 SO。
      猜你喜欢
      • 2019-06-19
      • 2020-04-07
      • 2021-06-17
      • 1970-01-01
      • 2020-10-01
      • 1970-01-01
      • 2020-10-26
      • 2019-10-02
      • 1970-01-01
      相关资源
      最近更新 更多