如何解决discord.js 中的冷却没有给出错误或工作
我正在尝试为我的处理程序添加冷却时间,这样我就不必在每个单独的命令中添加冷却时间。它没有发送任何错误或响应。
这是在消息事件处理程序中:
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
let command = client.commands.get(cmd);
//cooldowns
const cooldowns = new Discord.Collection();
if (!cooldowns.has(command.name)) {
cooldowns.set(command.name,new Discord.Collection());
}
const now = Date.now();
const timestamps = cooldowns.get(command.name);
const cooldownAmount = (command.cooldown || 3) * 1000;
if (timestamps.has(message.author.id)) {
const expirationTime = timestamps.get(message.author.id) + cooldownAmount;
if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000;
return message.reply(`please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`);
}
}
timestamps.set(message.author.id,now);
setTimeout(() => timestamps.delete(message.author.id),cooldownAmount);
//cooldowns
这是我在命令本身中的内容:
module.exports = {
name: 'tag',aliases: ['tags','t'],cooldown: 5,category: 'fun',description: 'Create a custom command',usage: `tag create|delete|edit`,run: (client,message,args) => {
return message.reply('test,command is not done yet this is to test the cooldown')
}}
我从这里得到了代码:https://discordjs.guide/command-handling/adding-features.html#cooldowns
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。