Compare commits

...

3 Commits

Author SHA1 Message Date
e0c581dcfd get specific permissions from parent element 2024-02-28 21:19:20 +01:00
84f754dd5b clean up: consistant naming 2024-02-28 21:18:14 +01:00
3cea3694db clean up: code style 2024-02-28 21:12:38 +01:00

View File

@ -4,7 +4,8 @@ import {
GuildMember,
GuildChannelManager,
GuildChannel,
VoiceState
VoiceState,
PermissionOverwrites
} from 'discord.js';
import { VoiceChannel } from '../../database.js';
@ -19,29 +20,34 @@ const getChannel = async (member, guildChs, channel) => {
// Check database for existing channel
const ownCh = await VoiceChannel.findOne({
where: {
owner: member.user.id
owner: member.id
}
});
if (ownCh !== null) {
return await guildChs.fetch(ownCh.id);
}
if (ownCh !== null) return await guildChs.fetch(ownCh.id);
// Create private channel with all permissions
const name = member.user.username;
const chName = `${name}${name.toLowerCase().endsWith('s') ? "'" : "'s"} channel`;
// Get permissions from parent
const vcPermOver = channel.parent.permissionOverwrites.cache.get(member.id);
/** @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: [vcPermOver]
permissionOverwrites: [
{
id: member.id,
allow,
deny
}
]
});
// Save newly created channel
await VoiceChannel.create({
id: privCh.id,
owner: member.user.id
owner: member.id
});
return privCh;