admin管理员组

文章数量:1293335

I would like to add some members to the specific channel in Guild so only they are able to see the channel. I am creating a new channel via this script

const channel = await guild.channels.create({
    parent: category.id,
    name: 'test-room',
    type: ChannelType.GuildText,
});

I would also like to add some specific role to this channel so each member of the role can see the channel

More clarification: imagine you have a channel for each member joined to the discord. Something like a support channel. Each one member has its own channel that only he and the support team can see. So I need to create a channel and add permissions for the support team and for the given user to be able to see and write to that channel

I would like to add some members to the specific channel in Guild so only they are able to see the channel. I am creating a new channel via this script

const channel = await guild.channels.create({
    parent: category.id,
    name: 'test-room',
    type: ChannelType.GuildText,
});

I would also like to add some specific role to this channel so each member of the role can see the channel

More clarification: imagine you have a channel for each member joined to the discord. Something like a support channel. Each one member has its own channel that only he and the support team can see. So I need to create a channel and add permissions for the support team and for the given user to be able to see and write to that channel

Share edited Feb 17 at 7:45 Kuba Šimonovský asked Feb 12 at 17:48 Kuba ŠimonovskýKuba Šimonovský 2,0412 gold badges18 silver badges37 bronze badges 4
  • what problem are you encountering? – G-Force Commented Feb 12 at 20:46
  • If I create a channel, everyone can see that channel. I need to set specific users who can see the channel – Kuba Šimonovský Commented Feb 17 at 7:46
  • so create a channel. create a role. assign permissions to the channel with what role(s) you want, with what permission(s) for each role(s). Then assign users to that role, and you have what you want. – G-Force Commented Feb 17 at 16:53
  • yeah and thats exactly what I asked.. how to programatically assign permissions to the channel.. – Kuba Šimonovský Commented Feb 22 at 16:15
Add a comment  | 

1 Answer 1

Reset to default 1

You can add permission overwrites to the channel:

const channel = await guild.channels.create({
    parent: category.id,
    name: 'test-room',
    type: ChannelType.GuildText,
    permissionOverwrites: [
        { // disallow everyone to see the channel
            id: guild.id,
            deny: [PermissionsBitField.Flags.ViewChannel],
        },
        { // allow the user to see the channel
            id: theUser.id,
            allow: [PermissionsBitField.Flags.ViewChannel],
        },
        { // allow the user to see the channel
            id: supportTeamRole.id,
            allow: [PermissionsBitField.Flags.ViewChannel],
        },
    ],
});

Then only the user and the admin can see this channel.
Further Information: Adding overwrites

本文标签: discordjs v14 add member to a channelStack Overflow