Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
109 views
in Technique[技术] by (71.8m points)

javascript - Permission overwrite isn't setting permissions

I don't know why is permissionOverwrites not working for me. No error here. No permissions will change for anyone. I think the problem is here: {allow: 'VIEW_CHANNEL', id: userId,}. I think the problem will be in the id. I hope someone finds out where I made a mistake.

module.exports = (client, Discord, chalk, message, args) => {
    const channelId = '799339037306912808'
  
    const getEmoji = (emojiName) =>
      client.emojis.cache.find((emoji) => emoji.name === emojiName)
  
    const emojis = {
      golden_ticket: 'rules',
    }
  
    const handleReaction = (reaction, user, add) => {
      if (user.id === '799652033509457940') {
        return
      }
  
      const emoji = reaction._emoji.name
  
      const { guild } = reaction.message
  
      const userName = user.username
      const userId = guild.members.cache.find((member) => member.id === user.id)
      const categoryId = '802172599836213258';
  
      if (add) {
        reaction.users.remove(userId)
        reaction.message.guild.channels
        .create(`${userName}`, {
            type: 'text',
            permissionOverwrites: [
                {
                    allow: 'VIEW_CHANNEL',
                    id: userId,
                }
            ],
        })
        .then((channel) => {
          channel.setParent(categoryId)
          channel => ticketChannelId = channel.id;
          message.ticketChannelId.send('cs');
        })
      } else {
        return;
      }
    }
  
    client.on('messageReactionAdd', (reaction, user) => {
      if (reaction.message.channel.id === channelId) {
        handleReaction(reaction, user, true)
      }
    })
  }
question from:https://stackoverflow.com/questions/65916920/permission-overwrite-isnt-setting-permissions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here, it is better to specify the type of the overwrite. Plus, "allow" should be an array.

permissionOverwrites: [
    {
        allow: [ 'VIEW_CHANNEL' ],
        id: userId,
        type: 'member'
    }
],

it should resolve your issue. Note that by default, your channel will be readable by everyone, use:

permissionOverwrites: [
    {
         deny: ['VIEW_CHANNEL'],
         id: reaction.message.guild.id,
         type: 'role'
    },
    {
        allow: ['VIEW_CHANNEL'],
        id: userId,
        type: 'member'
    }
],

so everyone can't see the channel except admins and the user


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...