如何在此代码应答之前为其添加1分钟的超时时间?
//cd test
client.on("message", (msg) => {
if(msg.content.toLowerCase().startsWith(`${PREFIX}1cd`)) {
let user = message.mentions.roles.first();
message.channel.send(`1 minute has passed <@${msg.author.id}>`)
}
});
//cd test
答案 0 :(得分:1)
赞:
setTimeout(() => {
// Code goes here
}, 60000)
答案 1 :(得分:1)
请参见setTimeout()
https://www.w3schools.com/jsref/met_win_settimeout.asp
client.on("message", (msg) => {
if(msg.content.toLowerCase().startsWith(`${PREFIX}1cd`)) {
//pass the code that you want to execute later as a callback function
setTimeout(() => {
let user = message.mentions.roles.first();
message.channel.send(`1 minute has passed <@${msg.author.id}>`)
}, 60000); //60s is 60000 ms, and it takes the amount of time as milliseconds
}
});