🥅 error handling in command handler

This commit is contained in:
Axel Olausson Holtenäs 2022-04-17 18:09:28 +02:00
parent 527a482b6c
commit 61ae59847d
No known key found for this signature in database
GPG key ID: 7BF6826B76382CBA

View file

@ -1,18 +1,18 @@
import fs from "fs"; // fs
import { Collection } from "discord.js"; // discord.js
import { Client } from "../types/common/discord";
import logger from "../logger";
import { Client } from "@root/types/common/discord";
import logger from "@logger";
export default async (client: Client) => {
client.commands = new Collection();
fs.readdir("./src/plugins", async (error, plugins) => {
if (error) {
return logger?.error(`Error reading plugins: ${error}`);
return logger.error(`Error reading plugins: ${error}`);
}
await Promise.all(
plugins?.map(async (pluginName) => {
plugins.map(async (pluginName) => {
const plugin = await import(`../plugins/${pluginName}`);
await client?.commands?.set(
@ -20,8 +20,14 @@ export default async (client: Client) => {
plugin?.default
);
logger?.verbose(`Loaded plugin: ${pluginName}`);
logger.verbose(`Loaded plugin: ${pluginName}`);
})
);
)
.then(async () => {
logger.debug("Successfully loaded plugins.");
})
.catch(async (err) => {
logger.error(err);
});
});
};