chomens-bot-js/util/loadPlugins.js
2022-11-16 09:33:16 +07:00

26 lines
749 B
JavaScript

const fs = require('fs/promises');
const util = require('util');
const path = require('path');
/**
* load plugins
* @param {object} bot the bot object
* @param {object} dcclient discord client
* @param {object} config the config
* @param {object} rl readline
*/
async function loadPlugins(bot, dcclient, config, rl) {
const plugins = await fs.readdir(path.join(__dirname, '..', 'plugins'));
plugins.forEach((plugin) => {
try {
const plug = require(path.join(__dirname, '..', 'plugins', plugin));
plug.inject(bot, dcclient, config, rl);
} catch (e) {
console.log(`Plugin ${plugin} is having exception loading the plugin:`);
console.log(util.inspect(e));
}
});
};
module.exports = {loadPlugins};