NodeJS 在discord.js v14中创建频道时继承类别的属性

ruoxqz4g  于 11个月前  发布在  Node.js
关注(0)|答案(1)|浏览(140)

我试图创建一个通道,默认情况下,它允许某些角色访问并阻止@everyone,但我也希望它能与类别一起工作,例如允许其他角色

let specificOverwrites = [
                ...members,
                {
                    id: creatorRoleId,
                    allow: [PermissionFlagsBits.ViewChannel]
                },
                {
                    id: interaction.guild.roles.everyone.id,
                    deny: [PermissionFlagsBits.ViewChannel]
                }
            ];

            // Use specificOverwrites during channel creation
            const channel = await interaction.guild.channels.create({
                name: allianceNameInput,
                type: ChannelType.GuildText,
                parent: alliancesCategory.id,
                permissionOverwrites: specificOverwrites
            });

字符串
上面的代码是我目前拥有的,但它忽略了类别权限。我如何使它与类别权限一起工作?

bvjveswy

bvjveswy1#

您可以Map父类别的permissionOverwrites,并将Map的权限添加到specificOverwrites数组。

let specificOverwrites = [
    ...members,
    {
        id: creatorRoleId,
        allow: [PermissionFlagsBits.ViewChannel]
    },
    {
        id: interaction.guild.roles.everyone.id,
        deny: [PermissionFlagsBits.ViewChannel]
    },
    ...alliancesCategory.permissionOverwrites.cache.map((p) => {
        return {
            id: p.id,
            allow: p.allow.toArray(),
            deny: p.deny.toArray(),
        };
    }),
];

// Use specificOverwrites during channel creation
const channel = await interaction.guild.channels.create({
    name: allianceNameInput,
    type: ChannelType.GuildText,
    parent: alliancesCategory.id,
    permissionOverwrites: specificOverwrites
});

字符串

相关问题