Guest User

Untitled

a guest
May 21st, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. const { REST, Routes } = require('discord.js');
  2. const { clientId, token } = require('./config.json');
  3. const fs = require('node:fs');
  4. const path = require('node:path');
  5.  
  6. const commands = [];
  7. // Grab all the command files from the commands directory you created earlier
  8. const foldersPath = path.join(__dirname, 'commands');
  9. const commandFolders = fs.readdirSync(foldersPath);
  10.  
  11. for (const folder of commandFolders) {
  12. // Grab all the command files from the commands directory you created earlier
  13. const commandsPath = path.join(foldersPath, folder);
  14. const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
  15. // Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
  16. for (const file of commandFiles) {
  17. const filePath = path.join(commandsPath, file);
  18. const command = require(filePath);
  19. if ('data' in command && 'execute' in command) {
  20. commands.push(command.data.toJSON());
  21. }
  22. else {
  23. console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
  24. }
  25. }
  26. }
  27.  
  28. // Construct and prepare an instance of the REST module
  29. const rest = new REST().setToken(token);
  30.  
  31. // and deploy your commands!
  32. (async () => {
  33. try {
  34. console.log(`Started refreshing ${commands.length} application (/) commands.`);
  35.  
  36. // The put method is used to fully refresh all commands in the guild with the current set
  37. const data = await rest.put(
  38. Routes.applicationGuildCommands(clientId),
  39. { body: commands },
  40. );
  41.  
  42. console.log(`Successfully reloaded ${data.length} application (/) commands.`);
  43. }
  44. catch (error) {
  45. // And of course, make sure you catch and log any errors!
  46. console.error(error);
  47. }
  48. })();
Advertisement
Add Comment
Please, Sign In to add comment