From b8adefd0936fde80d72e70e3445d4b7a9a62de39 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Sat, 23 Mar 2024 22:43:21 +0100 Subject: [PATCH] implement working version of custom channel permissions --- events/channels/voiceStateUpdate.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/events/channels/voiceStateUpdate.js b/events/channels/voiceStateUpdate.js index 910e8b1..5118b42 100644 --- a/events/channels/voiceStateUpdate.js +++ b/events/channels/voiceStateUpdate.js @@ -5,7 +5,7 @@ import { GuildChannelManager, GuildChannel, VoiceState, - PermissionOverwrites + PermissionsBitField } from 'discord.js'; import { VoiceChannel } from '../../database.js'; @@ -28,20 +28,10 @@ const getChannel = async (member, guildChs, channel) => { // Create private channel with all permissions const name = member.user.username; const chName = `${name}${name.toLowerCase().endsWith('s') ? "'" : "'s"} channel`; - // Get permissions from parent - /** @type {PermissionOverwrites} */ - const { allow, deny } = channel.parent.permissionOverwrites.cache.get(member.client.user.id); const privCh = await guildChs.create({ name: chName, parent: channel.parent, - type: ChannelType.GuildVoice, - permissionOverwrites: [ - { - id: member.id, - allow, - deny - } - ] + type: ChannelType.GuildVoice }); // Save newly created channel @@ -107,6 +97,19 @@ export async function execute(oldState, newState) { const channels = newState.guild.channels; const privCh = await getChannel(member, channels, channel); + step = 'edit permissions for'; + // Edit permissionOverwrites on channel for user + await privCh.permissionOverwrites.set([ + { + id: member.id, + allow: [ + PermissionsBitField.Flags.ViewChannel, + PermissionsBitField.Flags.ManageChannels, + PermissionsBitField.Flags.ManageRoles + ] + } + ]); + step = 'move to'; // Move user to private channel await newState.setChannel(privCh);