Home > Net >  js 13 discord buttons clicked one
js 13 discord buttons clicked one

Time:04-22

I am writing tickets to the system. Reports come to a special channel. There is an "accept" button, it works, but when more than one report arrives, if you click on the "accept" button, then all reports will be accepted

2 reports IMAGE

i clicked one IMAGE

client.on('interactionCreate', async interaction => {
                    if(interaction.isButton()) {
                        if (interaction.customId.includes(`acceptB`)) {
                             myacceptB.edit({embeds:[editEmbRep]})
                            interaction
                            let channelx =   interaction.guild.channels.cache.get(myreportChannel)
                            if(channelx){

                                  channelx.permissionOverwrites.edit(interaction.user.id,{ VIEW_CHANNEL: true,SEND_MESSAGES: true,ATTACH_FILES: true,READ_MESSAGE_HISTORY:true })}

Might need to use a unique idButton each time, but I don't know how to check that

CodePudding user response:

This code should only edit the message that the button clicked is attached to. There is no need for unique ID’s for each button when you edit the message the interaction is attached to.

client.on('interactionCreate', async interaction => {
    if(interaction.isButton()) {
        if (interaction.customId === `acceptB`) {
   
            const editEmbRep = new MessageEmbed()
                .setTitle('New Embed')
   
            interaction.message.edit({
                content: 'updated text', // to change the text
                embeds: [editEmbRep], // to change the embed
                components: [] // if you want to remove the button
            })
   
// Not sure what you are trying to do with this part so I didn’t do anything with it. 

            let channelx = interaction.guild.channels.cache.get(myreportChannel)
            if (channelx) {
                channelx.permissionOverwrites.edit(
                    interaction.user.id,
                    {
                        VIEW_CHANNEL: true,
                        SEND_MESSAGES: true,
                        ATTACH_FILES: true,
                        READ_MESSAGE_HISTORY:true
                    }
                )
            }
        }
    }
})
  • Related