Team Ai
Apppublic

Stryker-SC/Discord-Bot-VCMaster-JavaScript-Revamped

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes
deploy-commands.js47 linesDownload Raw Back to root
1const { REST, Routes } = require('discord.js');2const config = require('./config');3const fs = require('fs');4const path = require('path');5const logger = require('./utils/logger');6 7const commands = [];8const foldersPath = path.join(__dirname, 'commands');9const commandFolders = fs.readdirSync(foldersPath);10 11for (const folder of commandFolders) {12    const commandsPath = path.join(foldersPath, folder);13    const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));14    for (const file of commandFiles) {15        const filePath = path.join(commandsPath, file);16        const command = require(filePath);17        if ('data' in command && 'execute' in command) {18            commands.push(command.data.toJSON());19        } else {20            logger.warn(`[Command Loader] The command at ${filePath} is missing a required "data" or "execute" property.`);21        }22    }23}24 25const restOptions = { version: '10' };26if (process.env.REST_PROXY_URL) {27    restOptions.api = process.env.REST_PROXY_URL.replace(/\/+$/, '');28}29const rest = new REST(restOptions).setToken(config.token);30 31(async () => {32    try {33        logger.info(`[Deploy] Started refreshing ${commands.length} application (/) commands.`);34 35        // Global deployment36        const data = await rest.put(37            Routes.applicationCommands(config.clientId),38            { body: commands },39        );40        logger.info('[Deploy] Successfully reloaded application (/) commands globally.');41 42        logger.info(`[Deploy] Successfully reloaded ${data.length} application (/) commands.`);43    } catch (error) {44        logger.error('[Deploy] Failed to deploy commands:', error);45    }46})();47