From dc7bef73ee2a70b08a0ae71126427ccef80b0f2f Mon Sep 17 00:00:00 2001 From: Slincnik Date: Sat, 7 Dec 2024 14:53:11 +0300 Subject: [PATCH] fix(event): fixed not loading events --- base/newClient.js | 4 +++- handlers/event-handler/index.js | 30 +++++++++++++++++------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/base/newClient.js b/base/newClient.js index b1b4e2f1..ae3e9497 100644 --- a/base/newClient.js +++ b/base/newClient.js @@ -12,6 +12,8 @@ export class ExtendedClient extends Client { } async init() { - this.login(config.token).then(async () => await Promise.all([initCommands(), initEvents()]).catch(console.error)); + return this.login(config.token) + .then(async () => await Promise.all([initCommands(), initEvents()])) + .catch(console.error); } } diff --git a/handlers/event-handler/index.js b/handlers/event-handler/index.js index a1406c23..4179703d 100644 --- a/handlers/event-handler/index.js +++ b/handlers/event-handler/index.js @@ -11,22 +11,26 @@ export const init = async () => { }; const buildEvents = async () => { - const eventFilePaths = (await getFilePaths("./newEvents", true)).filter(path => path.endsWith(".js")); + try { + const eventFilePaths = (await getFilePaths("./newEvents", true)).filter(path => path.endsWith(".js")); - for (const eventFilePath of eventFilePaths) { - const { data, run } = await import(toFileURL(eventFilePath)); + for (const eventFilePath of eventFilePaths) { + const { data, run } = await import(toFileURL(eventFilePath)); - if (!data || !data.name) { - console.warn(`Event ${eventFilePath} does not have a data object or name`); - continue; + if (!data || !data.name) { + console.warn(`Event ${eventFilePath} does not have a data object or name`); + continue; + } + + if (typeof run !== "function") { + console.warn(`Event ${eventFilePath} does not have a run function or it is not a function`); + continue; + } + + events.push({ data, run }); } - - if (typeof run !== "function") { - console.warn(`Event ${eventFilePath} does not have a run function or it is not a function`); - continue; - } - - events.push({ data, run }); + } catch (error) { + console.error("Error build events: ", error); } };