How to disable a button after a click discord.js v13

Viewed 20

im trying to make the "Elevate To Management" button disable after someone has clicked it so that people dont spam ping the role by spamming the button.

    const collector = interaction.channel.createMessageComponentCollector({time: 1000 });



                const row = new MessageActionRow()
                    .addComponents(
                        new MessageButton()
                            .setCustomId('supportticket_close')
                            .setLabel('Close Ticket')
                            .setStyle("DANGER")
                            .setEmoji(''),

                            new MessageButton()
                            .setCustomId('supportticket_elevate')
                            .setLabel('Elevate To Management')
                            .setStyle("SECONDARY")
                            .setEmoji('⬆️')
                            
                    );
                    if (channel) await channel.send({ content: interaction.user.toString(), embeds: [embed], components: [row] });

collector.on('collect', async interaction => {
    if (interaction.customId === 'supportticket_elevate') {
        row.components[1].setDisabled(true) //disables but_1
        interaction.editReply({ components: [row] });
    }})
1 Answers

What's the problem, exactly? Are you recieving the "Interaction failed" dialog? If yes, try increasing the collector's time. Also try doing interaction.update() instead of interaction.editReply().

Related