Advertisement
OnlyYoussef

handler

Jul 28th, 2022
956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const dotenv = require('dotenv');
  2. dotenv.config();
  3.  
  4. const { REST } = require('@discordjs/rest');
  5. const { Routes } = require('discord-api-types/v9');
  6. const clientId = "Bot id here (required)"
  7. const token2 = process.env.TOKEN
  8. client.commands = new Collection();
  9. const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
  10.  
  11. for (const file of commandFiles) {
  12.     const command = require(`./commands/${file}`);
  13.     client.commands.set(command.name, command);
  14. }
  15. const commands = client.commands.map(({ execute, ...data }) => data);
  16.  
  17. // Register slash commands
  18. const rest = new REST({ version: '9' }).setToken(token2);
  19. console.log(chalk.blueBright('Started refreshing slash commands...'));
  20. // rest.put(
  21. //     Routes.applicationCommands(config.clientId), { body: commands },
  22. // );
  23.  rest.put(
  24.     Routes.applicationCommands(clientId),
  25.     { body: commands },
  26. );
  27. console.log(chalk.yellowBright(`Successfully reloaded ${commands.length} slash commands!`));
  28.  
  29. // When the client is ready, run this code (only once)
  30. client.once('ready', () => {
  31.     console.log(chalk.greenBright(`[API] Logged in as ${client.user.tag} \n ID : ${client.user.id}`))
  32.      
  33. });
  34.  
  35. // Our slash command handler
  36. client.on('interactionCreate', async interaction => {
  37.     if (!interaction.isCommand()) return;
  38.     if(!interaction.channel.guild)return;
  39.     const command = client.commands.get(interaction.commandName);
  40.  
  41.     if (!command) return;
  42.  
  43.     try {
  44.         await command.execute(client,interaction,db);
  45.     } catch (error) {
  46.         console.error(error);
  47.         await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
  48.     }
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement