Home > OS >  How can I set a button as disabled after the 15s has passed without any interaction?? Discord v14
How can I set a button as disabled after the 15s has passed without any interaction?? Discord v14

Time:08-06

const config = require('../../botconfig');

module.exports = {
name: 'invite',
description: 'Crimson and Server invites',
run: async (client, interaction, args) => {
   try {
   const inviteEmbed = new EmbedBuilder()
      .setDescription('**__Invite • Support__**\n\n<a:Arrow:735141069033046106> Want to invite Crimson to your server? Feel free to click on the **"Invite"** button.\n\n<a:Arrow:735141069033046106> Need additional help with Crimson? Come join us in our humble abode by clicking on the **"Support"** button.')
      .setColor('#EE1C25')
      .setFooter({ text: `Command Requested by: ${interaction.user.tag}`, iconURL: interaction.user.displayAvatarURL() })
      .setTimestamp()
      .setThumbnail(client.user.displayAvatarURL());

   let botInvite = new ButtonBuilder()
      .setStyle(ButtonStyle.Link)
      .setURL(`https://discord.com/`)
      .setLabel('Invite');

   let support = new ButtonBuilder()
      .setStyle(ButtonStyle.Link)
      .setURL('https://discord.gg/')
      .setLabel('Support');
    
   let del = new ButtonBuilder()
      .setLabel(`Close`)
      .setCustomId(`delete`)
      .setEmoji(`❌`)
      .setStyle(ButtonStyle.Danger);

   const inviteMsg = await interaction.reply({ embeds: [inviteEmbed], components: [new ActionRowBuilder().addComponents(botInvite, support, del)], fetchReply: true });

   const collector = inviteMsg.createMessageComponentCollector({ componentType: ComponentType.Button, time: 15000 });

   collector.on('collect', async i => {
      if (i.user.id === interaction.user.id) {
        console.log(`${i.user.tag} clicked on the ${i.customId} button.`);
      } else {
        await i.reply({ content: `This button is not for you!`, ephemeral: true });
      }

      if (i.id === 'delete') {
         inviteMsg.delete();
         interaction.delete();
     await i.reply.defer();
      }
   });
   
   collector.on('end', collected => {
      console.log(`Collected ${collected.size} interactions.`);
   });

   } catch (err) {
     console.log(err);
     return interaction.reply(`\`${err}\`.`);
   }
  }
};

I’ve been trying to mess around with it to see if i can but I’m running out of options to try

  • Related