愿所有的美好和期待都能如约而至

Discord.js|已设置命令冷却时间,但不起作用

发布时间:  来源:互联网  作者:匿名  标签:discord discord.js error Discord.js | Command Cooldown is set but not working ex  热度:37.5℃

本文介绍了Discord.js|已设置命令冷却时间,但不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,help命令当前设置为60 seconds,因为您可以在cooldown中看到,但无论我在那里输入什么,它都不起作用,仍然设置为小于1秒。我猜对于输出,请检查此问题包含的GIF

Message.js:

const Discord = require("discord.js");
const settings = require("../../config/settings.json");

const cooldowns = new Discord.Collection();

module.exports = async (client, message) => {
    if (message.author.bot) return;
    const prefixesdatabase = client.settings.ensure(message.guild.id, settings);

    if (!client.settings.get(message.guild.id, "prefix")) {
        client.settings.set(message.guild.id, {
            prefix: settings.prefix
        });
    }

    if (message.content.match(new RegExp(`^<@!?${client.user.id}>( |)$`))) {
        message.reply(`my prefix is: `${prefixesdatabase.prefix}``);
    }

    if (!message.content.startsWith(prefixesdatabase.prefix)) return;
    const command = message.content
        .split(" ")[0]
        .slice(prefixesdatabase.prefix.length);
    const args = message.content.split(" ").slice(1);
    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 || 2) * 1000;
    if (timestamps.has(message.author.id)) {
        const expirationTime = timestamps.get(message.author.id) + cooldownAmount;
        if (now < expirationTime) {
            const timeLeft = (expirationTime - now) / 2000;
            return message.reply(
                `Before using **${
                    prefixesdatabase.prefix
                }${command}**, please wait for **${timeLeft.toFixed(
                    1
                )} second for cooldowns!**`
            );
        }
    }
    timestamps.set(message.author.id, now);
    setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);
    let cmd;
    if (client.commands.has(command)) {
        cmd = client.commands.get(command);
    } else if (client.aliases.has(command)) {
        cmd = client.commands.get(client.aliases.get(command));
    }
    try {
        cmd.run(client, message, args);
    } catch (e) {
        return console.log(`Invalid command: ${command}`);
    } finally {
        console.log(
            `${message.author.username} using command ${prefixesdatabase.prefix}${command}`
        );
    }
};

help.js

const Discord = require("discord.js");

module.exports.run = async (client, message, args) => {
    const settings = require("../../config/settings.json");
    const prefixesdatabase = client.settings.ensure(message.guild.id, settings);

    const helpArray = message.content.split(" ");
    const helpArgs = helpArray.slice(1);

    if (!helpArgs[0]) {
        const embed = new Discord.MessageEmbed()
            .setColor("#b491c8")
            .setDescription(
                `**My prefix:** `${prefixesdatabase.prefix}` , Slash Commands list for `/help`
Click [HERE](https://discord.com/api/oauth2/authorize?client_id=${client.user.id}&permissions=8&scope=bot%20applications.commands) to invite me to your server.`
            )
            .addField("**:gear: Basic**", "`help`, `ping`, `vote`, `uptime`, `setprefix`")
            .addField(
                "**

勇敢去编程!

勇敢的热爱编程,未来的你一定会大放异彩,未来的生活一定会因编程更好!

TOP