basic error handling and comments

This commit is contained in:
Baipyrus 2024-02-07 17:40:29 +01:00
parent 1a3e7ac96b
commit b5079b6f40

View File

@ -1,16 +1,20 @@
import { PermissionsBitField } from 'discord.js'; import { ChannelType, Events, PermissionsBitField } from 'discord.js';
import { ChannelType, Events } from 'discord.js';
export const name = Events.VoiceStateUpdate; export const name = Events.VoiceStateUpdate;
export async function execute(_, state) { export async function execute(_, state) {
if (!state.channel) return; if (!state.channel) return;
// Extract user data
const member = state.member; const member = state.member;
const name = member.user.username; const name = member.user.username;
// Extract channel data
const channels = state.guild.channels; const channels = state.guild.channels;
try {
// Create private channel with all permissions
const chName = `${name}${name.endsWith('s') ? "'" : "'s"} channel`;
const privCh = await channels.create({ const privCh = await channels.create({
name: `${name}${name.endsWith('s') ? "'" : "'s"} channel`, name: chName,
type: ChannelType.GuildVoice, type: ChannelType.GuildVoice,
permissionOverwrites: [ permissionOverwrites: [
{ {
@ -22,7 +26,11 @@ export async function execute(_, state) {
] ]
}); });
// Move user to private channel
await state.setChannel(privCh); await state.setChannel(privCh);
console.info(`[INFO] User '${name}' created private channel with ID ${privCh.id}.`);
console.debug(`[DEBUG] User '${member}' created private channel!`); } catch (error) {
console.error(error);
await member.send('Could no create or move to channel! Please contact server staff.');
}
} }