generated from Baipyrus/DiscordJS-Template
basic chanel creation
This commit is contained in:
parent
a0eb75e4ee
commit
1a3e7ac96b
@ -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!`);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user