Build/project structure #142

Merged
BlackAngelTV merged 80 commits from build/project-structure into main 2026-09-23 14:31:21 +02:00
Showing only changes of commit 15e7279fc0 - Show all commits
+28
View File
@@ -0,0 +1,28 @@
import { readdir } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
const commandsDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'commands');
/**
* Loads every command module from src/commands/<category>/<name>.js.
* A command module exports: `data` (SlashCommandBuilder), `access` (ACCESS_LEVELS) and `execute`.
*/
export async function loadCommands() {
const entries = await readdir(commandsDir, { recursive: true, withFileTypes: true });
const commands = [];
for (const entry of entries) {
if (!entry.isFile() || !entry.name.endsWith('.js')) continue;
const filePath = path.join(entry.parentPath, entry.name);
const command = await import(pathToFileURL(filePath).href);
if (!command.data || typeof command.execute !== 'function') {
throw new Error(`Invalid command module: ${path.relative(commandsDir, filePath)}`);
}
commands.push(command);
}
return commands;
}