javascript - 如何进行倒计时编辑而不是一一发送消息?
问题描述
我正在做一个倒计时命令,到目前为止,这是我的代码:
let count = args[1]
const counter = setInterval(() => {
if (count > 0) {
message.channel.send(count)
count--
} else {
clearInterval(counter)
}
}, 1000)
现在,计时器发送的数字如下:
1
2
3
4
5
我只希望它在一条消息中,然后在不和谐中进行编辑。
以下是在 Discord.JS 中编辑的方法(示例):
message.channel.send('hi').then(m => {
m.edit('edited!')
})
知道怎么做吗?
解决方案
这应该做
let count = args[1]
let CountDownMessage;
const counter = setInterval(async () => {
if (count == args[1]) { //For the first time only
await message.channel.send(count).then( msg => { CountDownMessage = msg }
count -- ;
}else if (count > 0) {
CountDownMessage.edit(count);
count -- ;
} else {
CountDownMessage.edit("Time's up");
clearInterval(counter);
}
}, 1000);
现在您不必每次都创建一个函数
推荐阅读
- azure - 我可以在 Azure 数据工厂中创建自定义错误语句而不是自动生成错误语句吗
- python - 如何从 Tkinter GUI 中删除警告标签
- flutter - 如何更改颤振插件包名称
- c# - How to handle the Multiple datatype values entered in a textbox for searching purpose
- python - NumPy 中有 unstack 吗?
- python - 将 pyspark CommonCrawl 存储库部署到 EMR
- html - html列之间的空间
- php - 如何在php中通过Curl正确插入quickbase
- php - 在 php 中使用 ajax 从数据库中获取数据时,操作链接不起作用
- git - TFS GIT - 从大师那里获取最新信息