From 61ae59847db7811b7392d4d6b8a4ba95edcd5ec1 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 17 Apr 2022 18:09:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20error=20handling=20in=20command?= =?UTF-8?q?=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/commands.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/handlers/commands.ts b/src/handlers/commands.ts index d7b2e68..dd4df30 100644 --- a/src/handlers/commands.ts +++ b/src/handlers/commands.ts @@ -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); + }); }); };