覆盖权限不起作用| Discord.js 硕士

overwritePermissions not functioning| Discord.js MASTER

我正在将我的机器人转换为与 discord.js 的主分支一起工作 我得到了我的票证命令,他们改变了很多,我设法做了除了 overwritePermissions 部分之外的所有事情。我不确定为什么代码不起作用。 如果我删除底部的 2 overwritePermissions 部分,它工作正常,但所有 3 个都存在,none 执行。

        let role = message.channel.guild.defaultRole;
        let role2 = message.guild.roles.find(x => x.name === "Support Team");
        message.guild.channels.create(`ticket-test`, {type: 'text'}).then(c => {
            c.overwritePermissions({
                permissionOverwrites: [{
                    id: role.id,
                    deny: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                }]
            });
            c.overwritePermissions({
                permissionOverwrites: [{
                    id: role2.id,
                    deny: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                }]
            });
            c.overwritePermissions({
                permissionOverwrites: [{
                    id: message.author.id,
                    allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                }]
            });
        });

我完成了 console.log(role.id)console.log(role2.id,它们都显示了正确的 ID,只是没有执行代码。

无需重复 overwritePermissions() 方法,您只需首先在 channel creation options 中列出您的权限覆盖。 type 的默认值已经是文本频道,因此您也可以省略该选项。最后,您应该始终捕捉 Promise。

const everyone = message.guild.defaultRole;
const support = message.guild.roles.find(r => r.name === 'Support Team');

message.guild.channels.create('ticket-test', {
  permissionOverwrites: [
    {
      id: everyone.id,
      deny: 'VIEW_CHANNEL'
    }, {
      id: support.id,
      allow: 'VIEW_CHANNEL'
    }, {
      id: message.author.id,
      allow: 'VIEW_CHANNEL'
    }
  ]
}).catch(err => console.error(err));
let role2 = message.guild.roles.find(x => x.name === "Mods");

但如果你想 为此:

async function jointocreatechannel(user) {
  //log it 
  console.log(" :: " + user.member.user.username + "#" + user.member.user.discriminator + " :: Created a Support")
  //user.member.user.send("This can be used to message the member that a new room was created")
  await user.guild.channels.create(`${user.member.user.username}'s Support`, {
    type: 'voice',
    parent: "973217461577080903", //or set it as a category id
  }).then(async vc => {
    //move user to the new channel
    user.setChannel(vc);
    //set the new channel to the map
    jointocreatemap.set(`tempvoicechannel_${vc.guild.id}_${vc.id}`, vc.id);
    //change the permissions of the channel
    let role2 = message.guild.roles.find(x => x.name === "Mods");
    await vc.overwritePermissions([
      {
        id: user.id,
        allow: ['MANAGE_CHANNELS'],
      },
      {
        id: user.guild.id,  
        deny: ['VIEW_CHANNEL'],
      },
      {
        id: role2.id,
        deny: ['VIEW_CHANNEL'],
      },
    ]);
  })
}
}