admin管理员组

文章数量:1428988

I am currently writing a discord bot and i need it to create channel with specific permissions.

For example @everyone shouldn't have view_channel permission. What i have tried :

message.guild.channels.create("Channel Name", { type: "voice" })
                .then((newChannel) => { newChannel.overwritePermissions(
                        everyone.id,
                        {
                            VIEW_CHANNEL: false
                        });
                })

It creates the channel but permissions doesn't changing...
I am using "discord.js v12+" module.

I am currently writing a discord bot and i need it to create channel with specific permissions.

For example @everyone shouldn't have view_channel permission. What i have tried :

message.guild.channels.create("Channel Name", { type: "voice" })
                .then((newChannel) => { newChannel.overwritePermissions(
                        everyone.id,
                        {
                            VIEW_CHANNEL: false
                        });
                })

It creates the channel but permissions doesn't changing...
I am using "discord.js v12+" module.

Share Improve this question edited Jul 15, 2022 at 19:49 Jonas 129k103 gold badges328 silver badges405 bronze badges asked Sep 25, 2020 at 20:04 SbekSSbekS 301 silver badge6 bronze badges 1
  • 1 Instead of creating a variable for everyoneRole and using everyoneRole.id, you can just use message.guild.id. Fun fact, the @everyone role shares the same ID as the guild its in. – Lioness100 Commented Sep 25, 2020 at 21:33
Add a ment  | 

1 Answer 1

Reset to default 3

You can pass in the permissions when creating the channel

let everyoneRole = msg.guild.roles.cache.find(r => r.name === '@everyone');

message.guild.channels.create('channel name', {
  type: 'voice',
  permissionOverwrites: [
     {
       id: everyoneRole.id,
       deny: ['VIEW_CHANNEL'],
    },
  ],
})

本文标签: javascriptJS Discord BotCreating Channel With Specific Permissions ( v12 )Stack Overflow