2024-02-07 16:40:29 +00:00
|
|
|
import { ChannelType, Events, PermissionsBitField } from 'discord.js';
|
2024-01-28 17:33:22 +00:00
|
|
|
|
|
|
|
export const name = Events.VoiceStateUpdate;
|
2024-02-07 16:36:00 +00:00
|
|
|
export async function execute(_, state) {
|
|
|
|
if (!state.channel) return;
|
2024-01-28 17:33:22 +00:00
|
|
|
|
2024-02-07 16:40:29 +00:00
|
|
|
// Extract user data
|
2024-02-07 16:36:00 +00:00
|
|
|
const member = state.member;
|
|
|
|
const name = member.user.username;
|
2024-01-28 17:33:22 +00:00
|
|
|
|
2024-02-07 16:40:29 +00:00
|
|
|
// Extract channel data
|
2024-02-07 16:36:00 +00:00
|
|
|
const channels = state.guild.channels;
|
2024-02-07 16:40:29 +00:00
|
|
|
try {
|
|
|
|
// Create private channel with all permissions
|
|
|
|
const chName = `${name}${name.endsWith('s') ? "'" : "'s"} channel`;
|
|
|
|
const privCh = await channels.create({
|
|
|
|
name: chName,
|
|
|
|
type: ChannelType.GuildVoice,
|
|
|
|
permissionOverwrites: [
|
|
|
|
{
|
|
|
|
id: member.id,
|
|
|
|
allow: [
|
|
|
|
PermissionsBitField.All
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
2024-01-28 17:33:22 +00:00
|
|
|
|
2024-02-07 16:40:29 +00:00
|
|
|
// Move user to private channel
|
|
|
|
await state.setChannel(privCh);
|
|
|
|
console.info(`[INFO] User '${name}' created private channel with ID ${privCh.id}.`);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
await member.send('Could no create or move to channel! Please contact server staff.');
|
|
|
|
}
|
2024-01-28 17:33:22 +00:00
|
|
|
}
|