首页 > 解决方案 > 我如何制作一个也会扫描文件夹的命令处理程序?

问题描述

我正在制作一个不和谐的机器人,所以我已经做了太多的命令,现在我需要把它们放在他们自己的文件夹中,比如 moderation、misc 等。

const commandFlies = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));


for (const file of commandFlies) {
    const command = require(`./commands/misc/${file}`);

    // set a new item in the Collection
    // with the key as the command name and the value as the exported value
    client.commands.set(command.name, command);
}

const client = new Discord.Client();
const cooldowns = new Discord.Collection();
client.commands = new Discord.Collection();
const commandFlies = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));


for (const file of commandFlies) {
    const command = require(`./commands/${file}`);

    // set a new item in the Collection
    // with the key as the command name and the value as the exported value
    client.commands.set(command.name, command);
}

它一直告诉我它已经定义了。

标签: javascriptdiscord.js

解决方案


推荐阅读