Untitled
unknown
javascript
6 months ago
1.2 kB
4
Indexable
const { REST, Routes } = require('discord.js'); require('dotenv').config(); const fs = require('fs'); const path = require('path'); const commands = []; const commandsPath = path.join(__dirname, 'commands', 'slash'); const loadCommandsFromDir = (dir) => { const items = fs.readdirSync(dir, { withFileTypes: true }); for (const item of items) { const itemPath = path.join(dir, item.name); if (item.isDirectory()) { loadCommandsFromDir(itemPath); } else if (item.isFile() && item.name.endsWith('.js')) { const command = require(itemPath); if (command.data && typeof command.data.toJSON === 'function') { commands.push(command.data.toJSON()); } } } }; loadCommandsFromDir(commandsPath); const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN); (async () => { try { console.log('Started refreshing application (/) commands.'); await rest.put( Routes.applicationCommands(process.env.CLIENT_ID), { body: commands }, ); console.log('Successfully reloaded application (/) commands.'); } catch (error) { console.error(error); } })();
Editor is loading...
Leave a Comment