DudeThatsErin

interactionCreate.js

Sep 20th, 2021 (edited)
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const config = require('../config.json');
  2. const Discord = require('discord.js');
  3.  
  4. module.exports = {
  5.     name: 'interactionCreate',
  6.     async execute(interaction, client) {
  7.         console.log(interaction)
  8.         if (!interaction.isCommand()) return interaction.reply({ content: 'That is not a valid slash command.', ephermal: true });
  9.         if (!client.commands.has(interaction.commandName)) return;
  10.  
  11.         const command = client.commands.get(interaction.commandName);
  12.         if (!command) return interaction.reply({ content: 'This command no longer exists.', ephermal: true }) && client.commands.delete(interaction.commandName);
  13.  
  14.         // owner only
  15.         if (command.ownerOnly === 'yes') {
  16.             if (!interaction.user.id === config.developer.id) {
  17.                 return interaction.reply({ content: `This is only a command Erin (DudeThatsErin#8061) can use. If you are seeing this in error use the \`${prefix}report\` command.`, ephermal: true });
  18.             }
  19.         }
  20.  
  21.         // command cooldowns
  22.         if (!cooldowns.has(command.name)) {
  23.             cooldowns.set(command.name, new Discord.Collection());
  24.         }
  25.  
  26.         const now = Date.now();
  27.         const timestamps = cooldowns.get(command.name);
  28.         const cooldownAmount = (command.cooldown || 1) * 1000;
  29.  
  30.         if (timestamps.has(interaction.user.id)) {
  31.             const expirationTime = timestamps.get(interaction.user.id) + cooldownAmount;
  32.  
  33.             if (now < expirationTime) {
  34.                 const timeLeft = (expirationTime - now) / 1000;
  35.                 return interaction.reply({ content: `Please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`, ephermal: true });
  36.             }
  37.         }
  38.  
  39.         timestamps.set(interaction.user.id, now);
  40.         setTimeout(() => timestamps.delete(interaction.user.id), cooldownAmount);
  41.  
  42.         const modRoles = ['780941276602302523', '822500305353703434', '718253309101867008', '751526654781685912'];
  43.         const modIDs = ['732667572448657539', '455926927371534346', '541305895544422430'];
  44.         const isMod = modIDs.reduce((alrdyGod, crr) => alrdyGod || interaction.content.toLowerCase().split(' ').includes(crr), false);
  45.         let value = 0;
  46.         if (interaction.channel.parentID === '382210817636040706') {
  47.             for (const ID of modRoles) {
  48.                 if (!interaction.member.roles.cache.has(ID)) {
  49.                     value++
  50.                 }
  51.                 if (value != modRoles.length && isMod) {
  52.                     interaction.reply({ content: `Please do not ping the mods. If you need to contact them, please message <@575252669443211264> to open a ModMail ticket. Thank you!`, ephermal: true });
  53.                 }
  54.             }
  55.         }
  56.  
  57.         if (command.modOnly === 'yes') {
  58.             for (const ID of modRoles) {
  59.                 if (!interaction.member.roles.cache.has(ID)) {
  60.                     value++
  61.                 }
  62.  
  63.                 if (value == modRoles.length) {
  64.                     interaction.reply({ content: `This is a command only moderators can use. You do not have the required permissions. Moderators have the <@&${modRoles[0]}> role or <@&${modRoles[1]}> role or <@&${modRoles[2]}> role  or <@&${modRoles[3]}> role. Please run \`${config.bot.prefix}report [issue]\` if you are seeing this in error.`, ephermal: true });
  65.                     return;
  66.                 }
  67.             }
  68.         }
  69.  
  70.         const chllMod = ['839863262026924083', '718253309101867008'];
  71.         if (command.challengeMods === 'yes') {
  72.             for (const ID of chllMod) {
  73.                 if (!interaction.member.roles.cache.has(ID)) {
  74.                     value++
  75.                 }
  76.                 if (value == chllMod.length) {
  77.                     interaction.reply({ content: `This is a command only challenge moderators can use. You do not have the required permissions. Challenge moderators have the <@&${chllMod[1]}> role. Please run \`${config.bot.prefix}report [issue]\` if you are seeing this in error.`, ephermal: true });
  78.                     return;
  79.                 }
  80.             }
  81.         }
  82.  
  83.         // actually running the commands.
  84.         try {
  85.             await client.commands.get(interaction.commandName).execute(interaction, client);
  86.         } catch (error) {
  87.             console.error(error);
  88.             const embed = new Discord.MessageEmbed()
  89.                 .setColor('RED')
  90.                 .setTitle('Oh no! An _error_ has appeared!')
  91.                 .setDescription(`**Contact Bot Owner:** <@${config.bot.ownerID}>`)
  92.                 .addFields({
  93.                     name: '**Error Name:**',
  94.                     value: `\`${error.name}\``
  95.                 }, {
  96.                     name: '**Error Message:**',
  97.                     value: `\`${error.message}\``
  98.                 }, {
  99.                     name: '**Error Location:**',
  100.                     value: `\`${error.stack}\``
  101.                 }, {
  102.                     name: '**Ways to Report:**',
  103.                     value: `Run the \`${config.bot.prefix}report\` command, [Join My Support Server](https://discord.gg/tT3VEW8AYF), [Fill out this form](https://codinghelp.site/contact-us/) (Erin owns CodingHelp so that form goes directly to her), Message her on Discord, or Email her at me@dudethatserin.site\n\nPlease include all of the information in this embed (message) as well as any additional information you can think to provide. Screenshots are also VERY helpful. Thank you!`
  104.                 })
  105.                 .setTimestamp()
  106.                 .setFooter(`Thanks for using ${client.user.tag}! I'm sorry you encountered this error!`, `${client.user.displayAvatarURL()}`)
  107.            interaction.reply({ embeds: [embed], ephermal: true });
  108.        }
  109.    }
  110. };
Add Comment
Please, Sign In to add comment