camerond33

interactionCreate.js

Jun 1st, 2022 (edited)
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { MessageButton, MessageActionRow } = require('discord.js');
  2.  
  3. module.exports = {
  4.     name: 'interactionCreate',
  5.     async execute(interaction, client) {
  6.         if (interaction.isCommand()) {
  7.         const command = client.slash.get(interaction.commandName); // We need to change this to the new collection called slash. You can change the name to whatever you want but you need to do it in index.js as well
  8.         if(!command) return;
  9.  
  10.         try{
  11.             await command.execute(interaction);
  12.         }catch(error){
  13.             console.error(error);
  14.             await interaction.reply({content : "There was an error while executing action"})
  15.         }
  16.  
  17.         console.log(`${interaction.user.tag} in #${interaction.channel.name} triggered an interaction.`);
  18.         return;
  19.  
  20.     } else if (interaction.isButton()) {
  21.         interaction.reply("you clicked" + interaction.customId);
  22.         console.log(interaction);
  23.  
  24.         if (interaction.customId === 'offensebank') {
  25.             console.log(`${interaction.user.tag} in #${interaction.channel.name} clicked the offense button.`);
  26.        
  27.             const ActionRow = new MessageActionRow()
  28.             .setComponents(
  29.                 new MessageButton()
  30.                     .setCustomId('ambulance')
  31.                     .setLabel('Ambulance')
  32.                     .setStyle('PRIMARY'),
  33.  
  34.                     new MessageButton()
  35.                     .setCustomId('construction')
  36.                     .setLabel('Construction')
  37.                     .setStyle('PRIMARY'),
  38.                    
  39.                     new MessageButton()
  40.                     .setCustomId('housefront')
  41.                     .setLabel('House Front')
  42.                     .setStyle('PRIMARY'));
  43.        
  44.             return interaction.update({
  45.               content: 'Choose your spawn site',
  46.               components: [ActionRow],
  47.               ephemeral: true
  48.             });
  49.         }
  50.         else if (interaction.customId === 'defensebank') {
  51.             console.log(`${interaction.user.tag} in #${interaction.channel.name} clicked the offense button.`);
  52.  
  53.             const ActionRow = new MessageActionRow()
  54.             .setComponents(
  55.                 new MessageButton()
  56.                     .setCustomId('kids')
  57.                     .setLabel('Kids')
  58.                     .setStyle('PRIMARY'),
  59.  
  60.                     new MessageButton()
  61.                     .setCustomId('laundry')
  62.                     .setLabel('Laundry')
  63.                     .setStyle('PRIMARY'),
  64.                    
  65.                     new MessageButton()
  66.                     .setCustomId('kitchen')
  67.                     .setLabel('Kitchen')
  68.                     .setStyle('PRIMARY'));
  69.        
  70.             return interaction.update({
  71.               content: 'Choose the site your defending',
  72.               components: [ActionRow],
  73.               ephemeral: true
  74.             });
  75.            
  76.         }
  77.        
  78.     }
  79.     },
  80. };
Add Comment
Please, Sign In to add comment