【问题标题】:Discord bot: send message and wait to send another oneDiscord bot:发送消息并等待发送另一条消息
【发布时间】:2020-12-30 02:05:29
【问题描述】:

我希望我的机器人发送一条消息,然后等待 1-2 秒,然后再发送另一条消息。我正在使用 discord.js。我尝试在互联网上四处寻找,但找不到任何适合我的情况。

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    您可以使用setTimeout 将一段代码设置为在给定持续时间后运行。

    channel.send("First message...")
        .then(() => { // Wait until the first message is sent
             setTimeout(() => {
                 channel.send("Second message...");
             }, 2000) // Wait 2000 milliseconds (2 seconds) before sending again.
        })
    

    【讨论】:

      猜你喜欢
      • 2021-01-12
      • 2020-12-01
      • 2021-03-02
      • 2021-06-05
      • 1970-01-01
      • 2023-03-22
      • 2020-12-03
      • 2021-09-17
      • 2021-06-17
      相关资源
      最近更新 更多