implement working version of custom channel permissions

This commit is contained in:
Baipyrus 2024-03-23 22:43:21 +01:00
parent c7aad7190e
commit b8adefd093

View File

@ -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);