basic chanel creation

This commit is contained in:
Baipyrus 2024-02-07 17:36:00 +01:00
parent a0eb75e4ee
commit 1a3e7ac96b

View File

@ -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;
console.debug(`[DEBUG] User '${member}' ${state} channel '${channel}' in guild '${guild}'.`);
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
]
}
]
});
await state.setChannel(privCh);
console.debug(`[DEBUG] User '${member}' created private channel!`);
}