Files
star-kitten/packages/discord/src/commands/import-commands.ts

20 lines
781 B
TypeScript

import { Glob } from 'bun';
import { join } from 'node:path';
import type { ApplicationCommandStructure } from '@projectdysnomia/dysnomia';
import type { CommandHandler } from '../types';
export async function importCommands(
pattern: string = '**/*.command.{js,ts,jsx,tsx}',
baseDir: string = join(process.cwd(), 'src'),
commandRegistry: Record<string, CommandHandler<ApplicationCommandStructure>> = {},
): Promise<Record<string, CommandHandler<ApplicationCommandStructure>>> {
const glob = new Glob(pattern);
for await (const file of glob.scan({ cwd: baseDir, absolute: true })) {
const command = (await import(file)).default as CommandHandler<ApplicationCommandStructure>;
commandRegistry[command.definition.name] = command;
}
return commandRegistry;
}