generated from Baipyrus/DiscordJS-Template
Compare commits
3 Commits
fa6a9fa2e3
...
e0c581dcfd
Author | SHA1 | Date | |
---|---|---|---|
e0c581dcfd | |||
84f754dd5b | |||
3cea3694db |
@ -4,7 +4,8 @@ import {
|
|||||||
GuildMember,
|
GuildMember,
|
||||||
GuildChannelManager,
|
GuildChannelManager,
|
||||||
GuildChannel,
|
GuildChannel,
|
||||||
VoiceState
|
VoiceState,
|
||||||
|
PermissionOverwrites
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { VoiceChannel } from '../../database.js';
|
import { VoiceChannel } from '../../database.js';
|
||||||
|
|
||||||
@ -19,29 +20,34 @@ const getChannel = async (member, guildChs, channel) => {
|
|||||||
// Check database for existing channel
|
// Check database for existing channel
|
||||||
const ownCh = await VoiceChannel.findOne({
|
const ownCh = await VoiceChannel.findOne({
|
||||||
where: {
|
where: {
|
||||||
owner: member.user.id
|
owner: member.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (ownCh !== null) {
|
if (ownCh !== null) return await guildChs.fetch(ownCh.id);
|
||||||
return await guildChs.fetch(ownCh.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create private channel with all permissions
|
// Create private channel with all permissions
|
||||||
const name = member.user.username;
|
const name = member.user.username;
|
||||||
const chName = `${name}${name.toLowerCase().endsWith('s') ? "'" : "'s"} channel`;
|
const chName = `${name}${name.toLowerCase().endsWith('s') ? "'" : "'s"} channel`;
|
||||||
// Get permissions from parent
|
// 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({
|
const privCh = await guildChs.create({
|
||||||
name: chName,
|
name: chName,
|
||||||
parent: channel.parent,
|
parent: channel.parent,
|
||||||
type: ChannelType.GuildVoice,
|
type: ChannelType.GuildVoice,
|
||||||
permissionOverwrites: [vcPermOver]
|
permissionOverwrites: [
|
||||||
|
{
|
||||||
|
id: member.id,
|
||||||
|
allow,
|
||||||
|
deny
|
||||||
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save newly created channel
|
// Save newly created channel
|
||||||
await VoiceChannel.create({
|
await VoiceChannel.create({
|
||||||
id: privCh.id,
|
id: privCh.id,
|
||||||
owner: member.user.id
|
owner: member.id
|
||||||
});
|
});
|
||||||
|
|
||||||
return privCh;
|
return privCh;
|
||||||
|
Loading…
Reference in New Issue
Block a user