// greetz https://github.com/discordeno/discordeno/blob/main/examples/advanced/src/utils/loader.ts import { readdir } from 'node:fs/promises' import { join } from 'node:path' export async function importDirectory(folder: string): Promise { const files = await readdir(folder, { recursive: true }) // bot.logger.info(files) for (const filename of files) { if (!filename.endsWith('.js') && !filename.endsWith('.ts')) continue console.log(`loading ${filename}`) // Using `file://` and `process.cwd()` to avoid weird issues with relative paths and/or Windows // await import(`file://${process.cwd()}/${folder}/${filename}`).catch((x) => await import(join(folder, filename)).catch((x) => // console.error(x) console.error(`cannot import ${filename} for reason: ${x}`) // logger.fatal(`Cannot import file (${folder}/${filename}) for reason: ${x}`), ) } }