Add Discord.js bot base with prefix commands and Winston logging

Co-authored-by: yhqe <139268606+yhqe@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]andyhqe committed 2026-03-12 23:32:21 +00:00
1 parent 8bd000a57a
commit e8049008eb
12 files changed
+1076 -2

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
'use strict';
const fs = require('fs');
const path = require('path');
const logger = require('../utils/logger');
/**
* Loads all command files from src/commands and registers them on the client.
* Each command file must export: { name, description, aliases?, usage?, execute }
*
* @param {import('discord.js').Client} client
*/
function loadCommands(client) {
const commandsPath = path.join(__dirname, '..', 'commands');
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith('.js'));
let loaded = 0;
for (const file of commandFiles) {
try {
const command = require(path.join(commandsPath, file));
if (!command.name || typeof command.execute !== 'function') {
logger.warn(
`[CommandHandler] Skipping ${file}: missing "name" or "execute".`,
);
continue;
}
client.commands.set(command.name.toLowerCase(), command);
// Register aliases if provided
if (Array.isArray(command.aliases)) {
for (const alias of command.aliases) {
client.commands.set(alias.toLowerCase(), command);
}
}
logger.debug(`[CommandHandler] Loaded command: ${command.name}`);
loaded++;
} catch (err) {
logger.error(`[CommandHandler] Failed to load ${file}:`, err);
}
}
logger.info(`[CommandHandler] ${loaded} command(s) loaded.`);
}
module.exports = { loadCommands };