Add /ban-role moderation command and improve module loading

This commit is contained in:
2026-09-27 01:04:44 +02:00
parent 65a281dbcb
commit a7f8263931
13 changed files with 959 additions and 56 deletions
+30 -2
View File
@@ -1,15 +1,43 @@
const path = require('node:path');
const { REST, Routes } = require('discord.js');
const { clientId, token } = require('./config.json');
const { getConfigValue } = require('./config');
const { loadCommandModules } = require('./loaders/commands');
const commandsPath = path.join(__dirname, 'commands');
const { commands, invalidCommands } = loadCommandModules(commandsPath);
const {
commands,
duplicateCommands,
invalidCommands,
loadErrors,
} = loadCommandModules(commandsPath);
const commandsData = commands.map((command) => command.data.toJSON());
const clientId = getConfigValue('DISCORD_CLIENT_ID', 'discordClientId', 'clientId', 'appId');
const token = getConfigValue('DISCORD_BOT_TOKEN', 'discordBotToken', 'token');
for (const filePath of invalidCommands) {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
for (const { commandName, filePath, existingFilePath } of duplicateCommands) {
console.error(
`[ERROR] Duplicate command name "${commandName}" in ${filePath}. Already registered by ${existingFilePath}.`,
);
}
for (const { filePath, error } of loadErrors) {
console.error(`[ERROR] Failed to load command at ${filePath}:`, error);
}
if (!clientId || !token) {
console.error('Missing Discord client ID or bot token. Set env vars or config.json values.');
process.exit(1);
}
if (duplicateCommands.length > 0 || loadErrors.length > 0) {
console.error('Command deployment aborted because one or more command modules failed validation.');
process.exit(1);
}
const rest = new REST().setToken(token);
(async () => {