Search code examples
node.jsdiscord.js

how to make a button collector that increases the time left when you click


   let time = 10;
        const collector = msg.createMessageComponentCollector({time:1000*time})
 collector.on("collect", async (btn) => {

let embed = new Discord.EmbedBuilder()
                embed.setColor(0xff0000)
                embed.setAuthor({name:`${btn.user.username}`, iconURL:btn.user.displayAvatar({dynamic:true}))
                embed.setTitle(`You clicked`)
msg.edit{embeds:[embed]}
 time = 10;
})

        collector.on('end',(reason)=>{
            row.components.forEach(bt => {
                bt.setDisabled(true);
               });
      
                msg.edit({components:[row]})
        })

I tried this but I have no idea how to increase the time of the collector but it stops after 10 seconds


Solution

  • I think you're looking for something called as Collector#resetTimer
    It basically resets the timer and you can easily use this while listening to collect event.

    For example

    collector.on('collect', (i) => {
       if (i.customId !== 'reset') return;
       collector.resetTimer();
    })
    

    Do note that you can provide custom time as well using the CollectorResetTimerOptions