我正在尝试使用talkedRecently进行冷却,但它不起作用,请帮助我。
const talkedRecently = new Set();
module.exports = {
name: 'c',
description: 'c!',
execute(message, args) {
if (talkedRecently.has(message.member.id)) {
message.channel.send("You should wait 1 minute before use this command again")
} else if(!talkedRecently.has(message.member.id)){
message.channel.send("Your id sucsesfully added to talkedRecently")
talkedRecently.add(message.member.id)
setTimeout(() => {talkedRecently.delete(message.author.id), 60000})
console.log(talkedRecently)
}
},
};发布于 2021-07-11 18:54:42
首先,我们需要做一套新的
var cooldown = new Set()在你的消息事件中,让机器人检查用户是否处于冷却状态
if(cooldown.has(msg.author.id)) return msg.reply("You're in cooldown")如果用户未处于冷却状态,则将他添加到冷却状态并回复他
cooldown.add(message.author.id)我们需要在给他一段时间后解除他的冷却时间,使用setTimeout
setTimeout(() => {
cooldown.delete(message.author.id)
},3500)发布于 2021-07-11 18:54:17
这是因为您的setTimeout语法是错误的。这应该是语法。
setTimeout(() => { talkedRecently.delete(message.author.id); }, 60000);https://stackoverflow.com/questions/68335377
复制相似问题