有没有办法让每个人冷静一下?我尝试了很多选项,但它们往往会出错,就像每个人都在使用该命令一样,而不仅仅是一个人。到目前为止,我的代码:
const talkedRecently = new Set();
module.exports = {
name: 'ping',
description: "The bot will respond with pong",
execute(message, args){
message.channel.send('pong!');
}
}
答案 0 :(得分:0)
我用这个(根据您的需要修改):
const talkedRecently = new Set();
module.exports = {
name: 'ping',
description: "The bot will respond with pong",
execute(message, args){
var cooldown = '15000' // cooldown in miliseconds
var cooldownMessage = 'this command has a 15 seconds cooldown'
if (talkedRecently.has(message.author.id)) {
message.reply(`${cooldownMessage}`);
} else {
// your code here:
message.channel.send('pong!');
talkedRecently.add(message.author.id);
setTimeout(() => {
// Removes the user from the set after the cooldown
talkedRecently.delete(message.author.id);
}, cooldown);
}
}
}