From b5079b6f40c0a32da3691c82975a2bd3a4770891 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Wed, 7 Feb 2024 17:40:29 +0100 Subject: [PATCH] basic error handling and comments --- events/channels/voiceStateUpdate.js | 42 +++++++++++++++++------------ 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/events/channels/voiceStateUpdate.js b/events/channels/voiceStateUpdate.js index 2fe381d..a48b01b 100644 --- a/events/channels/voiceStateUpdate.js +++ b/events/channels/voiceStateUpdate.js @@ -1,28 +1,36 @@ -import { PermissionsBitField } from 'discord.js'; -import { ChannelType, Events } from 'discord.js'; +import { ChannelType, Events, PermissionsBitField } from 'discord.js'; export const name = Events.VoiceStateUpdate; export async function execute(_, state) { if (!state.channel) return; + // Extract user data const member = state.member; const name = member.user.username; + // Extract channel data const channels = state.guild.channels; - const privCh = await channels.create({ - name: `${name}${name.endsWith('s') ? "'" : "'s"} channel`, - type: ChannelType.GuildVoice, - permissionOverwrites: [ - { - id: member.id, - allow: [ - PermissionsBitField.All - ] - } - ] - }); + 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 + ] + } + ] + }); - await state.setChannel(privCh); - - console.debug(`[DEBUG] User '${member}' created private channel!`); + // 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.'); + } }