diff --git a/events/channels/voiceStateUpdate.js b/events/channels/voiceStateUpdate.js index d698ca5..2fe381d 100644 --- a/events/channels/voiceStateUpdate.js +++ b/events/channels/voiceStateUpdate.js @@ -1,16 +1,28 @@ -import { Events } from 'discord.js'; +import { PermissionsBitField } from 'discord.js'; +import { ChannelType, Events } from 'discord.js'; export const name = Events.VoiceStateUpdate; -export async function execute(oldState, newState) { - console.debug('[DEBUG] Voice State Update'); +export async function execute(_, state) { + if (!state.channel) return; - const change = !!oldState.channel ^ !!newState.channel; - if (!change) return; + const member = state.member; + const name = member.user.username; - const guild = newState.guild.name; - const member = newState.member.user.username; - const state = newState.channel ? 'joined' : 'left'; - const channel = (oldState.channel ?? newState.channel).name; + 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 + ] + } + ] + }); - console.debug(`[DEBUG] User '${member}' ${state} channel '${channel}' in guild '${guild}'.`); + await state.setChannel(privCh); + + console.debug(`[DEBUG] User '${member}' created private channel!`); }