generated from Baipyrus/DiscordJS-Template
basic error handling and comments
This commit is contained in:
parent
1a3e7ac96b
commit
b5079b6f40
@ -1,28 +1,36 @@
|
|||||||
import { PermissionsBitField } from 'discord.js';
|
import { ChannelType, Events, PermissionsBitField } from 'discord.js';
|
||||||
import { ChannelType, Events } from 'discord.js';
|
|
||||||
|
|
||||||
export const name = Events.VoiceStateUpdate;
|
export const name = Events.VoiceStateUpdate;
|
||||||
export async function execute(_, state) {
|
export async function execute(_, state) {
|
||||||
if (!state.channel) return;
|
if (!state.channel) return;
|
||||||
|
|
||||||
|
// Extract user data
|
||||||
const member = state.member;
|
const member = state.member;
|
||||||
const name = member.user.username;
|
const name = member.user.username;
|
||||||
|
|
||||||
|
// Extract channel data
|
||||||
const channels = state.guild.channels;
|
const channels = state.guild.channels;
|
||||||
const privCh = await channels.create({
|
try {
|
||||||
name: `${name}${name.endsWith('s') ? "'" : "'s"} channel`,
|
// Create private channel with all permissions
|
||||||
type: ChannelType.GuildVoice,
|
const chName = `${name}${name.endsWith('s') ? "'" : "'s"} channel`;
|
||||||
permissionOverwrites: [
|
const privCh = await channels.create({
|
||||||
{
|
name: chName,
|
||||||
id: member.id,
|
type: ChannelType.GuildVoice,
|
||||||
allow: [
|
permissionOverwrites: [
|
||||||
PermissionsBitField.All
|
{
|
||||||
]
|
id: member.id,
|
||||||
}
|
allow: [
|
||||||
]
|
PermissionsBitField.All
|
||||||
});
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
await state.setChannel(privCh);
|
// Move user to private channel
|
||||||
|
await state.setChannel(privCh);
|
||||||
console.debug(`[DEBUG] User '${member}' created private channel!`);
|
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.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user