Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

333
Vistas
Discord js 13 button edit permission channel

When a person sends my command, a channel is created that only they have access to. Also, when creating a channel, a message is sent with the "accept" button, when another person clicks on the button, his rights in the created channel should be added. I can add rights, but when more than one message with a button arrives in a special channel, the person who clicked the button is added to all created channels

An example of how it works An example of how it works

let myreportChannel = ''
await interaction.guild.channels.create(channelNameMy, {
    type: 'text', parent: `${categoryTiket}`, permissionOverwrites: [

        {
            id: `${permUser}`, // permUser - who sent the command
            allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY', 'ATTACH_FILES']
        },
        {
            id: `${evryOneRolle}`,
            deny: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY']
        },


    ]
})
    //Prvivate embed
    .then(async reportChannel => {
        const exampleEmbed = new MessageEmbed()
            .setDescription(`Reported: <@${tagBan.id}>\nReason: ${reason}\ntiket: <#${reportChannel.id}>`)
            .setColor("#2F3136")
            .setImage(`${settings.reportgif}`)

        myreportChannel = reportChannel.id // save new channel id


        await interaction.reply({embeds: [exampleEmbed], ephemeral: true})


        //Report embed
        const reportEmbed = new MessageEmbed()
            .setDescription(`Intruder: ${tagBan}\nReason: ${reason}`)
            .setColor("#2F3136")
            .setImage(`${settings.reportgif}`)


        await client.channels.cache.get(`${reportChannel.id}`).send({
            embeds: [reportEmbed]
        })
    })




client.on('interactionCreate', async interaction => {
    if (interaction.isButton()) {
        if (interaction.customId.includes(`acceptB`)) {

            const editEmbRep = new MessageEmbed()
                .setDescription(`Author: <@${interaction.user.id}>\nIntruder: <@${tagBan.id}>\nStatus: ${dmStatusAc}\nTiket: <#${myreportChannel}>`)
                .setColor("#2F3136")
                .setImage(`${settings.reportgif}`)


            interaction.message.edit({
                content: 'updated text',
                embeds: [editEmbRep],
                components: []
            })

            let channelx = interaction.guild.channels.cache.get(myreportChannel) // set channel by id
            if (channelx) {

                channelx.permissionOverwrites.edit(interaction.user.id, {
                    VIEW_CHANNEL: true,
                    SEND_MESSAGES: true,
                    ATTACH_FILES: true,
                    READ_MESSAGE_HISTORY: true
                })  //edit permision channel. add the permission of the user who clicked on the "accept" button
                }
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

So I adjusted the code above and made some notes along the way, but this should work as expected. I split the command from the button push.

const reportChannel = await interaction.guild.channels.create(channelNameMy, {
    type: 'text',
    parent: `${categoryTiket}`,
    permissionOverwrites: [{
            id: `${permUser}`, // permUser - who sent the command
            allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY', 'ATTACH_FILES']
        },
        {
            id: `${evryOneRolle}`,
            deny: ['VIEW_CHANNEL'] //denying view channel will stop all other ones from working too
        },
    ]
})
//Prvivate embed
const exampleEmbed = new MessageEmbed()
    .setDescription(`Reported: <@${tagBan.id}>\nReason: ${reason}\nticket: <#${reportChannel.id}>`)
    .setColor("#2F3136")
    .setImage(`${settings.reportgif}`)

interaction.reply({
    embeds: [exampleEmbed],
    ephemeral: true
})


//Report embed
const reportEmbed = new MessageEmbed()
    .setDescription(`Intruder: ${tagBan}\nReason: ${reason}\nticket:<#${reportChannel.id}>`)
    .setColor("#2F3136")
    .setImage(`${settings.reportgif}`)
    .setFooter({
        text: `${reportChannel.id}` // I added the channel ID here again (critical part of the code to not change
    })
// adds the new channel id to the footer to be used later when someone clicks the accept button

const acceptButton = new MessageActionRow()
    .addComponents(
        new MessageButton()
        .setCustomId(`acceptB`)
        .setLabel('Accept')
        .setStyle('SUCCESS')
        .setEmoji('✅')
    )


client.channels.cache.get(reportChannel.id).send({
    embeds: [reportEmbed],
    components: [acceptButton]
})
client.on('interactionCreate', async interaction => {
    if (interaction.isButton()) {
        if (interaction.customId.includes(`acceptB`)) {
            // when someone clicks the accept button it grabs the embed
            const oldEmbed = interaction.message.embeds[0]
            // adds a line to that embed
            const editEmbRep = new MessageEmbed()
                .addField('Status:', `${dmStatusAc}`)
            // updates the embed and removes the button
            interaction.message.edit({
                embeds: [editEmbRep],
                components: []
            })
            // finds the channel using the channel id placed in the footer earlier
            const channelx = interaction.guild.channels.cache.get(oldEmbed.footer.text)

            channelx.permissionOverwrites.edit(interaction.user.id, {
                VIEW_CHANNEL: true,
                SEND_MESSAGES: true,
                ATTACH_FILES: true,
                READ_MESSAGE_HISTORY: true
            }) // adds them to the channel
        }
    }
})
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda