Hey everyone! I’m working on a Discord bot project using JavaScript and I need some help. When someone types a specific command, I want my bot to make a new text channel that only certain people can see and use.
Basically, the channel should be hidden from everyone else on the server except for the person who ran the command and my bot. I know how to create regular channels but I’m stuck on the permission part. How do I set it up so the channel is private and only includes specific users?
Any code examples would be really helpful. Thanks!
yea, just set the permissionOverwrites while creating the channel. deny the @everyone view_channel permission then allow it for specific users and your bot. use guild.channels.create() with the permissions as an array. should work like a charm!
Had this exact problem with my first moderation bot. The other answers missed something important - role-based permissions can mess you up. Users might have roles that override individual permissions, causing weird access issues you won’t expect. Also, wrap your channel creation in error handling. It’ll fail if your bot doesn’t have the right server permissions or you hit Discord’s channel limits. My bot crashed constantly during testing because I didn’t do this. The permission structure they mentioned works, but store the channel ID somewhere if you need it later. Especially for temp channels that need cleanup.
To create a private channel in Discord, utilize permissionOverwrites during the channel creation. Deny the VIEW_CHANNEL permission for @everyone, then allow it specifically for the user who executed the command and your bot. The following example demonstrates how to implement this: guild.channels.create('channel-name', { type: 'GUILD_TEXT', permissionOverwrites: [{ id: guild.id, deny: ['VIEW_CHANNEL'] }, { id: interaction.user.id, allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'] }, { id: client.user.id, allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'] }] }). Also, ensure that your bot has the ‘Manage Channels’ permission to prevent any errors.