Guest User

Untitled

a guest
Dec 25th, 2022
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. const { EmbedBuilder, Collection, PermissionsBitField } = require('discord.js');
  2. const ms = require('ms');
  3. const client = require('..');
  4. const config = require('../config.json');
  5.  
  6. const cooldown = new Collection();
  7.  
  8. client.on('interactionCreate', async interaction => {
  9. const slashCommand = client.slashCommands.get(interaction.commandName);
  10. if (interaction.type == 4) {
  11. if(slashCommand.autocomplete) {
  12. const choices = [];
  13. await slashCommand.autocomplete(interaction, choices)
  14. }
  15. }
  16. if (!interaction.type == 2) return;
  17.  
  18. if(!slashCommand) return client.slashCommands.delete(interaction.commandName);
  19. try {
  20. if(slashCommand.cooldown) {
  21. if(cooldown.has(`slash-${slashCommand.name}${interaction.user.id}`)) return interaction.reply({ content: config.messages["COOLDOWN_MESSAGE"].replace('<duration>', ms(cooldown.get(`slash-${slashCommand.name}${interaction.user.id}`) - Date.now(), {long : true}) ) })
  22. if(slashCommand.userPerms || slashCommand.botPerms) {
  23. if(!interaction.memberPermissions.has(PermissionsBitField.resolve(slashCommand.userPerms || []))) {
  24. const userPerms = new EmbedBuilder()
  25. .setDescription(`🚫 ${interaction.user}, You don't have \`${slashCommand.userPerms}\` permissions to use this command!`)
  26. .setColor('Red')
  27. return interaction.reply({ embeds: [userPerms] })
  28. }
  29. if(!interaction.guild.members.cache.get(client.user.id).permissions.has(PermissionsBitField.resolve(slashCommand.botPerms || []))) {
  30. const botPerms = new EmbedBuilder()
  31. .setDescription(`🚫 ${interaction.user}, I don't have \`${slashCommand.botPerms}\` permissions to use this command!`)
  32. .setColor('Red')
  33. return interaction.reply({ embeds: [botPerms] })
  34. }
  35.  
  36. }
  37.  
  38. await slashCommand.run(client, interaction);
  39. cooldown.set(`slash-${slashCommand.name}${interaction.user.id}`, Date.now() + slashCommand.cooldown)
  40. setTimeout(() => {
  41. cooldown.delete(`slash-${slashCommand.name}${interaction.user.id}`)
  42. }, slashCommand.cooldown)
  43. } else {
  44. if(slashCommand.userPerms || slashCommand.botPerms) {
  45. if(!interaction.memberPermissions.has(PermissionsBitField.resolve(slashCommand.userPerms || []))) {
  46. const userPerms = new EmbedBuilder()
  47. .setDescription(`🚫 ${interaction.user}, You don't have \`${slashCommand.userPerms}\` permissions to use this command!`)
  48. .setColor('Red')
  49. return interaction.reply({ embeds: [userPerms] })
  50. }
  51. if(!interaction.guild.members.cache.get(client.user.id).permissions.has(PermissionsBitField.resolve(slashCommand.botPerms || []))) {
  52. const botPerms = new EmbedBuilder()
  53. .setDescription(`🚫 ${interaction.user}, I don't have \`${slashCommand.botPerms}\` permissions to use this command!`)
  54. .setColor('Red')
  55. return interaction.reply({ embeds: [botPerms] })
  56. }
  57.  
  58. }
  59. await slashCommand.run(client, interaction);
  60. }
  61. } catch (error) {
  62. console.log(error);
  63. }
  64. });
Add Comment
Please, Sign In to add comment