deploy.js 788 B

123456789101112131415161718192021222324252627
  1. const { REST, Routes } = require('discord.js');
  2. const { clientId, guildId, token } = require('./config.json');
  3. const fs = require('node:fs');
  4. const commands = [];
  5. const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
  6. for (const file of commandFiles) {
  7. const command = require(`./commands/${file}`);
  8. commands.push(command.data.toJSON());
  9. }
  10. const rest = new REST({ version: '10' }).setToken(token);
  11. (async () => {
  12. try {
  13. console.log(`Started refreshing ${commands.length} application (/) commands.`);
  14. const data = await rest.put(
  15. Routes.applicationGuildCommands(clientId, guildId),
  16. { body: commands },
  17. );
  18. console.log(`Successfully reloaded ${data.length} application (/) commands.`);
  19. } catch (error) {
  20. console.error(error);
  21. }
  22. })();