[英]How to make a cooldown for a specific user for all commands (Discord.js)
一个用户正在向我的命令发送垃圾邮件,我该如何让所有命令对该特定用户具有相同的冷却时间?
这是我当前的代码
if (talkedRecently.has(msg.author.id)) {
msg.channel.send("Wait before getting typing this again. - " + msg.author);
} else {
message
channel.send('Cooldown over')
talkedRecently.add(msg.author.id);
setTimeout(() => {
talkedRecently.delete(msg.author.id);
}, 6000);
}
它不起作用,因为只有 1 个命令,我希望该特定用户的所有命令冷却下来。
您可以创建一个 function 以在用户运行以下命令时执行:
var usersOnCooldown = {};
function setCooldown(userId){
usersOnCooldown[userId] = true;
setTimeout(() => {
usersOnCooldown[userId] = false;
}, 5000);
}
function checkUserCooldown(userId){
return !(userId in usersOnCooldown) || !usersOnCooldown[userId];
}
您可以在每个命令之后调用setCooldown()
。 并在每个命令之前checkUserCooldown()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.