この質問にはすでに答えがあります:
JavaScriptで遅延時間を設定する方法
(答えは6つ)
3 年前
に閉店しました。
ping コマンドの作成に成功し、ボットの ping を計算しました。ただし、結果を送信する前に約 2 秒の遅延が必要です。
これが私のコードです:
module.exports = {
name: 'ping',
description: "shows the bot/'s ping",
execute(message, args) {
message.channel.send('`ping is being calculated...`').then(msg => {
const ping = msg.createdTimestamp - message.createdTimestamp;
msg.channel.send('`bot\'s` ping: ' + ping + "`ms`")
})
}
}
setTimeout を試してみましたか?
– セブラー
2020 年 9 月 3 日 21:34
------------------------
setTimeout(() => {code}, timeMs) を使用すると、まさにそれが実現されます。
module.exports = {
name: 'ping',
description: "shows the bot/'s ping",
execute(message, args) {
message.channel.send('`ping is being calculated...`').then(msg => {
setTimeout(() => {
const ping = msg.createdTimestamp - message.createdTimestamp;
msg.channel.send('`bot\'s` ping: ' + ping + "`ms`")
}, 2000)
})
}
}