44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
const { REST, Routes } = require('discord.js');
|
|
const { clientId, token } = require('./config.json');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const updateCommands = () => {
|
|
const commands = [];
|
|
const foldersPath = path.join(__dirname, 'commands');
|
|
|
|
for (const folder of fs.readdirSync(foldersPath)) {
|
|
const commandsPath = path.join(foldersPath, folder);
|
|
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 ('data' in command && 'execute' in command) {
|
|
commands.push(command.data.toJSON());
|
|
} else {
|
|
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
|
}
|
|
}
|
|
}
|
|
|
|
const rest = new REST().setToken(token);
|
|
|
|
(async () => {
|
|
try {
|
|
console.log(`⚙️ Started refreshing ${commands.length} application (/) commands.`);
|
|
|
|
const data = await rest.put(
|
|
Routes.applicationCommands(clientId),
|
|
{ body: commands },
|
|
);
|
|
|
|
console.log(`✅ Successfully reloaded ${data.length} application (/) commands.`);
|
|
} catch (error) {
|
|
console.error(`❌ ${error}`);
|
|
}
|
|
})();
|
|
}
|
|
|
|
module.exports = {
|
|
updateCommands
|
|
} |