Initial commit

This commit is contained in:
2024-09-03 20:18:41 +00:00
parent d5074296fe
commit 06ae61f8be
20 changed files with 2937 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
import path from 'path';
import { glob } from 'glob';
import { ApplicationCommand } from 'discord.js';
/**
* Get all command modules from the commands directory.
* @returns {Promise<string[]>} The file paths of all command modules.
*/
async function getCommandModulePaths() {
return await glob(path.join(process.cwd(), 'src/commands/**/*.js'));
}
/**
* Load a single command module.
* @param {string} modulePath The path to the command module.
* @returns {Promise<ApplicationCommand>} The loaded command module.
*/
async function loadCommandModule(modulePath) {
try {
const module = await import(path.resolve(modulePath));
const commandModule = module.default;
if (!commandModule.data || !commandModule.execute) {
console.warn(`Invalid command module at ${modulePath}`);
return;
}
console.info(`Loaded command module: ${commandModule.data.name}`);
return commandModule;
} catch (error) {
console.error(`Error loading module at ${modulePath}.`, error);
}
}
/**
* Load all command modules.
* @returns {Promise<ApplicationCommand[]>} The loaded command modules.
*/
export async function loadCommandModules() {
const commandModulePaths = await getCommandModulePaths();
const commandModules = await Promise.all(
commandModulePaths.map(loadCommandModule)
);
return commandModules.filter((module) => module);
}