javascript - 我如何制作一个也会扫描文件夹的命令处理程序?
问题描述
我正在制作一个不和谐的机器人,所以我已经做了太多的命令,现在我需要把它们放在他们自己的文件夹中,比如 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);
}
它一直告诉我它已经定义了。
解决方案
推荐阅读
- c# - 对象 C# 的二维数组
- c - 使用 Glade 的非常简单的 GtkGLArea 示例
- c++ - c ++初始化类的char数组成员
- mvvm - 绑定 List 时出现 NullReferenceException
Xamarin.Forms 中的 Control 和 ViewModel 之间 - gulp - 如何检查任务是否作为 gulp@4 中另一个任务的依赖项运行?
- xpath - 当其中一个是可选的时,如何通过 xpath 在不同级别选择两个不同的标签
- android - 室内安卓地图
- sql-server - 检测同一数据列中日期差异的样本
- c# - ModelState.IsValid 总是返回错误的编辑表单
- ios - iOS Common Crypto Decrypt RC4 加密视频文件内存崩溃