Home > Back-end >  Discord js v12 Add rights to a channel if user reacts to a specific message
Discord js v12 Add rights to a channel if user reacts to a specific message

Time:12-02

I have a problem that I can't solve: Every time someone reacts to a specific message a channel gets created, and then the person who reacted first is the only one who has the permissions to see this channel. I set the max amount of reactions to "2", and I want it so that the second person who reacts with the message also gets permissions to see the created channel, but I don't know how to do it. Does somebody has an example? This is what I currently have:

 message.guild.channels.create("Busfahrer", {
                    type: "text",
                    parent: category,
                    permissionOverwrites: [
                        {
                            id: message.guild.id,
                            allow: ['SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES', 'READ_MESSAGE_HISTORY'],
                            deny: ['VIEW_CHANNEL'],                                
                        }
                    ]
                })

CodePudding user response:

Keep track of who reacts first and second and only give it to the second person:

const collector = reactionMessage2p.createReactionCollector(filter2p, {max: 2, time: 20000, errors: ['time'] })
let reactedUsers = []

collector.on("collect", (reaction, user) => {
  reactedUsers.push(user.id)
})

collector.on("end", async () => {
  let targetUser = reactedUsers[1]
  // channel is the channel you create
  channel.updateOverwrite(targetUser, {
    VIEW_CHANNEL: true
  })
})

I got some of this code from your other question

  • Related