Advertisement
camerond33

deploy-commands.js

Jun 1st, 2022
980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('node:fs');
  2. const path = require('node:path');
  3. const { REST } = require('@discordjs/rest');
  4. const { Routes } = require('discord-api-types/v9');
  5. const { clientId, guildId, token } = require('./config.json');
  6.  
  7.  
  8. const commands = [];
  9.  
  10.  
  11. const commandsPath = path.join(__dirname, 'commands');
  12. const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
  13.  
  14. for (const file of commandFiles) {
  15.     const filePath = path.join(commandsPath, file);
  16.     const command = require(filePath)
  17.     commands.push(command.data.toJSON());
  18. }
  19.  
  20.  
  21. const rest = new REST({ version: '9' }).setToken(token);
  22.  
  23. (async () => {
  24.     try {
  25.         console.log('Started refreshing application (/) commands.');
  26.  
  27.         await rest.put(
  28.             Routes.applicationGuildCommands(clientId, guildId),
  29.             { body: commands },
  30.         );
  31.  
  32.         console.log('Successfully reloaded application (/) commands.');
  33.     } catch (error) {
  34.         console.error(error);
  35.     }
  36.  
  37. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement