41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
require('dotenv').config({ path: '../backend/.env' });
|
|
const { REST, Routes } = require('discord.js');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const commands = [];
|
|
const commandsPath = path.join(__dirname, 'commands');
|
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
|
|
|
for (const file of commandFiles) {
|
|
const filePath = path.join(commandsPath, file);
|
|
const command = require(filePath);
|
|
if (command.enabled === false || command.dev === true) continue;
|
|
|
|
if (command.builder) {
|
|
commands.push(command.builder.toJSON());
|
|
} else {
|
|
commands.push({ name: command.name, description: command.description });
|
|
}
|
|
}
|
|
|
|
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN);
|
|
|
|
const deployCommands = async (guildId) => {
|
|
try {
|
|
// Minimal logging: indicate a refresh is happening (no per-guild spam)
|
|
console.log('🔁 Refreshing application commands...');
|
|
|
|
await rest.put(
|
|
Routes.applicationGuildCommands(process.env.DISCORD_CLIENT_ID, guildId),
|
|
{ body: commands },
|
|
);
|
|
|
|
console.log(`✅ Reloaded application commands (${commands.length} commands)`);
|
|
} catch (error) {
|
|
console.error('Failed to deploy commands:', error && error.message ? error.message : error);
|
|
}
|
|
};
|
|
|
|
module.exports = deployCommands;
|