javascript - 在继续代码之前让机器人等待一段时间
问题描述
有没有办法让机器人在继续代码之前等待一段时间(例如 5 秒)?我需要类似的东西:
client.on('messageCreate', message => {
message.channel.send('1st message')
wait(5000)
message.channel.send('2nd message')
wait(5000)
message.channel.send('3rd message')
})
就像许多人建议的那样,我尝试使用setInterval
,但这似乎不是我的解决方案。我也不能使用await setTimeout(time)
,因为SyntaxError: await is only valid in async functions and the top level bodies of modules
和TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received 5000
解决方案
推荐阅读
- python - 如何有效地查询大型 LDIF 文件?
- html - CSS first-of-type 适用于所有
- gitlab - 如何回滚到以前版本的 Gitlab
- c# - 如何在列表框中获取特定字符
- php - Laravel:有没有办法删除数据库查询子句?
- llvm - macOS homebrew llvm clang tidy 缺少一些检查
- javascript - 谢谢 URL 没有在 iframe 表单之外加载
- android - 在 Flutter 项目的 android studio 上初始化 Gradle 将永远存在
- android - Flutter 在 android Barcode Scanner 上隐藏屏幕键盘
- r - 从 DT 中的选定行计算累积值