'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

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
}
Solution 1:[1]
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
}
}
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gh0st |
