fix(event): fixed not loading events

This commit is contained in:
Slincnik 2024-12-07 14:53:11 +03:00
parent 3d91b7fa9b
commit dc7bef73ee
No known key found for this signature in database
2 changed files with 20 additions and 14 deletions

View file

@ -12,6 +12,8 @@ export class ExtendedClient extends Client {
} }
async init() { 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);
} }
} }

View file

@ -11,22 +11,26 @@ export const init = async () => {
}; };
const buildEvents = 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) { for (const eventFilePath of eventFilePaths) {
const { data, run } = await import(toFileURL(eventFilePath)); const { data, run } = await import(toFileURL(eventFilePath));
if (!data || !data.name) { if (!data || !data.name) {
console.warn(`Event ${eventFilePath} does not have a data object or name`); console.warn(`Event ${eventFilePath} does not have a data object or name`);
continue; 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 });
} }
} catch (error) {
if (typeof run !== "function") { console.error("Error build events: ", error);
console.warn(`Event ${eventFilePath} does not have a run function or it is not a function`);
continue;
}
events.push({ data, run });
} }
}; };