Dynamic event loader not working properly

This is my event loader:
import { readdirSync } from "fs"
import { fileURLToPath } from "url"

import type { ClientEvent } from "events/events"
import type { KannaBot } from "types"

const EVENT_DIR = fileURLToPath(new URL("../events/", import.meta.url))

export default function eventLoader(client: KannaBot) {
readdirSync(EVENT_DIR)
.filter(file => file.endsWith(".js"))
.forEach(async eventFile => {
console.debug(`Loading event ${eventFile}...`)
const loadedEvent = await import(`${EVENT_DIR}${eventFile}`)
const event = loadedEvent.default as ClientEvent
client.on(event.eventName, event.callback)
console.debug(`Loaded event ${event.eventName}`)
})
}
import { readdirSync } from "fs"
import { fileURLToPath } from "url"

import type { ClientEvent } from "events/events"
import type { KannaBot } from "types"

const EVENT_DIR = fileURLToPath(new URL("../events/", import.meta.url))

export default function eventLoader(client: KannaBot) {
readdirSync(EVENT_DIR)
.filter(file => file.endsWith(".js"))
.forEach(async eventFile => {
console.debug(`Loading event ${eventFile}...`)
const loadedEvent = await import(`${EVENT_DIR}${eventFile}`)
const event = loadedEvent.default as ClientEvent
client.on(event.eventName, event.callback)
console.debug(`Loaded event ${event.eventName}`)
})
}
Run command:
npx tsc && node build/KannaBot.js
npx tsc && node build/KannaBot.js
File structure:
KannaBot/
| events
| channelCreate.ts
| guildCreate.ts
| guildDelete.ts
| guildMemberAdd.ts
| messageCreate.ts
| messageUpdate.ts
| ready.ts
KannaBot/
| events
| channelCreate.ts
| guildCreate.ts
| guildDelete.ts
| guildMemberAdd.ts
| messageCreate.ts
| messageUpdate.ts
| ready.ts
Somehow only 2 events are only being imported
2 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
https://vsus.app
https://vsus.appOP2y ago
node -v
v16.19.0
node -v
v16.19.0
There aren't any error either oh true gotta check that out oh lol thx so much swallowed all of the errors
Want results from more Discord servers?
Add your server