61 lines
1.9 KiB
JavaScript
61 lines
1.9 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);
|
|
}
|
|
};
|
|
|
|
// Standalone execution
|
|
if (require.main === module) {
|
|
const { Client, GatewayIntentBits } = require('discord.js');
|
|
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
|
|
|
client.once('ready', async () => {
|
|
console.log(`Logged in as ${client.user.tag}`);
|
|
console.log(`Deploying commands to ${client.guilds.cache.size} guilds...`);
|
|
|
|
for (const [guildId, guild] of client.guilds.cache) {
|
|
await deployCommands(guildId);
|
|
}
|
|
|
|
console.log('All commands deployed!');
|
|
client.destroy();
|
|
});
|
|
|
|
client.login(process.env.DISCORD_BOT_TOKEN);
|
|
}
|
|
|
|
module.exports = deployCommands;
|