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 const name = Events.VoiceStateUpdate;
export async function execute(oldState, newState) { export async function execute(_, state) {
console.debug('[DEBUG] Voice State Update'); if (!state.channel) return;
const change = !!oldState.channel ^ !!newState.channel; const member = state.member;
if (!change) return; const name = member.user.username;
const guild = newState.guild.name; const channels = state.guild.channels;
const member = newState.member.user.username; const privCh = await channels.create({
const state = newState.channel ? 'joined' : 'left'; name: `${name}${name.endsWith('s') ? "'" : "'s"} channel`,
const channel = (oldState.channel ?? newState.channel).name; type: ChannelType.GuildVoice,
permissionOverwrites: [
console.debug(`[DEBUG] User '${member}' ${state} channel '${channel}' in guild '${guild}'.`); {
id: member.id,
allow: [
PermissionsBitField.All
]
}
]
});
await state.setChannel(privCh);
console.debug(`[DEBUG] User '${member}' created private channel!`);
} }