Files
NitoriBot/src/util/loadModules.js
T

26 lines
948 B
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) {
2025-01-15 11:32:27 -05:00
bot.modules = [];
2024-07-07 15:44:16 -04:00
for (const filename of fs.readdirSync(path.join(__dirname, '../', 'modules'))) {
try {
2024-11-22 12:49:22 -05:00
if (filename.endsWith(".js")) {
const module = require(path.join(__dirname, '../modules', filename));
2025-01-15 11:32:27 -05:00
if (module.data.enabled === false) {
bot.modules.push(module);
} else {
module.inject({ bot, options, config, discordClient });
bot.modules.push(module);
}
2024-11-22 12:49:22 -05:00
} if (filename.endsWith(".mjs")) {
const module = await import(path.join(__dirname, '../modules', filename));
2025-01-15 11:32:27 -05:00
module.default({ bot, options, config, discordClient });
2024-10-23 10:33:14 -04:00
}
2024-07-07 15:44:16 -04:00
} catch (error) {
2024-11-22 12:49:22 -05:00
console.error(`Failed to load module ${filename} due to error`);
console.error(`\x1b[31m${error.stack}\x1b[0m`);
2024-07-07 15:44:16 -04:00
}
}
}
module.exports = loadModules;