权限覆盖不是设置权限

时间:2021-01-27 10:09:50

标签: javascript discord discord.js

我不知道为什么 permissionOverwrites 对我不起作用。这里没有错误。任何人的权限都不会改变。我认为问题出在这里:{allow: 'VIEW_CHANNEL', id: userId,}。我认为问题将出在 id 上。我希望有人发现我哪里出错了。

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)
      }
    })
  }

1 个答案:

答案 0 :(得分:1)

这里最好指定覆盖的类型。另外,“允许”应该是一个数组。

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

它应该可以解决您的问题。请注意,默认情况下,每个人都可以阅读您的频道,请使用:

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

所以除了管理员和用户之外,每个人都看不到频道