Advertisement
Guest User

Deploy Commands.js

a guest
Jul 20th, 2023
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | Source Code | 0 0
  1. const commands = [];
  2. const foldersPath = path.join(__dirname, 'commands');
  3. const commandFolders = fs.readdirSync(foldersPath);
  4.  
  5. for (const folder of commandFolders) {
  6. const commandsPath = path.join(foldersPath, folder);
  7. const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
  8. for (const file of commandFiles) {
  9. const filePath = path.join(commandsPath, file);
  10. const command = require(filePath);
  11. if ('data' in command && 'execute' in command) {
  12. commands.push(command.data.toJSON());
  13. } else {
  14. console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
  15. }
  16. }
  17. }
  18.  
  19. const rest = new REST().setToken(token);
  20.  
  21. (async () => {
  22. try {
  23. console.log('Before resetting global commands...');
  24. await rest.put(
  25. Routes.applicationCommands(clientId),
  26. { body: [] },
  27. );
  28. console.log('After resetting global commands...');
  29. } catch (error) {
  30. console.error('Failed to reset global commands:', error);
  31. }
  32. })();
  33.  
  34. (async () => {
  35. try {
  36. console.log('Before resetting guild commands...');
  37. await rest.put(
  38. Routes.applicationGuildCommands(clientId, guildId),
  39. { body: [] },
  40. );
  41. console.log('After resetting guild commands...');
  42. } catch (error) {
  43. console.error('Failed to reset guild commands:', error);
  44. }
  45. })();
  46.  
  47. (async () => {
  48. try {
  49. console.log(`Started refreshing ${commands.length} application (/) commands.`);
  50.  
  51. const data = await rest.put(
  52. Routes.applicationCommands(clientId),
  53. { body: commands },
  54. );
  55.  
  56. console.log(`Successfully reloaded ${data.length} application (/) commands.`);
  57. } catch (error) {
  58. console.error('Failed to register commands:', error);
  59. }
  60. })();
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement