Files
NitoriBot/src/util/loadModules.js
T

39 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-07-07 15:44:16 -04:00
const fs = require("fs");
const path = require("path");
2024-10-23 10:33:14 -04:00
async function loadModules (bot, options, config, discordClient) {
// let module
2024-07-07 15:44:16 -04:00
bot.loadModule = module => module(bot, options, config, discordClient)
for (const filename of fs.readdirSync(path.join(__dirname, '../', 'modules'))) {
try {
2024-10-23 10:33:14 -04:00
if (filename.endsWith(".mjs")) {
// const module = await import(path.join(__dirname, '../', 'modules', filename));
// bot.loadModule(module);
} else if (filename.endsWith(".js")) {
const module = require(path.join(__dirname, '../', 'modules', filename));
bot.loadModule(module);
}
//bot.loadModule(module)
2024-07-07 15:44:16 -04:00
} catch (error) {
console.error('Failed to load module', filename, ':', error)
}
}
}
module.exports = loadModules;
2024-10-23 10:33:14 -04:00
/*
for (const filename of fs.readdirSync(path.join(__dirname, '../commands'))) {
try {
if (filename.endsWith('.mjs')) {
let commands = await import(path.join(__dirname, '../commands', filename))
bot.commandManager.register(commands.command);
bot.commandManager.commandlist.push(commands.command);
} if (filename.endsWith('.js')) {
let commands = require(path.join(__dirname, '../commands', filename));
bot.commandManager.register(commands);
bot.commandManager.commandlist.push(commands);
}
} catch (error) {
console.error('Failed to load command', filename, ':', error)
}
}
*/