generated from Baipyrus/DiscordJS-Template
Compare commits
No commits in common. "d0ec7fbb6c6897807231840d1cce8dc3283ce56b" and "c8e3fc2f2c53add43edd46b2e02d69118412fc51" have entirely different histories.
d0ec7fbb6c
...
c8e3fc2f2c
@ -1,5 +1,4 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { VoiceChannel } from '../../../database.js';
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName('custom_vc')
|
||||
@ -28,47 +27,6 @@ export const data = new SlashCommandBuilder()
|
||||
)
|
||||
);
|
||||
export async function execute(interaction) {
|
||||
const { guild, options } = interaction;
|
||||
|
||||
let step;
|
||||
try {
|
||||
switch (options.getSubcommand()) {
|
||||
case 'create': {
|
||||
// Get channel name from user input
|
||||
const name = options.getString('name');
|
||||
|
||||
step = 'create';
|
||||
// Create new channel
|
||||
const channel = await guild.create({
|
||||
name, type: ChannelType.GuildVoice
|
||||
});
|
||||
|
||||
// Save channel data
|
||||
step = 'save';
|
||||
await VoiceChannel.create({ id: channel.id });
|
||||
break;
|
||||
}
|
||||
case 'register': {
|
||||
// Get channel id from user input
|
||||
const id = options.getString('id');
|
||||
|
||||
step = 'fetch';
|
||||
// Try fetching channel by id
|
||||
await guild.channels.fetch(id);
|
||||
|
||||
// Save channel data
|
||||
step = 'save';
|
||||
await VoiceChannel.create({ id });
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
// Reply failed to acknowledge command
|
||||
await interaction.reply({
|
||||
content: `Failed to ${step} message!`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
const { options } = interaction;
|
||||
// const id = options.getString('id');
|
||||
}
|
||||
|
@ -1,36 +1,16 @@
|
||||
import { ChannelType, Events, PermissionsBitField } from 'discord.js';
|
||||
import { Events } from 'discord.js';
|
||||
|
||||
export const name = Events.VoiceStateUpdate;
|
||||
export async function execute(_, state) {
|
||||
if (!state.channel) return;
|
||||
export async function execute(oldState, newState) {
|
||||
console.debug('[DEBUG] Voice State Update');
|
||||
|
||||
// Extract user data
|
||||
const member = state.member;
|
||||
const name = member.user.username;
|
||||
const change = !!oldState.channel ^ !!newState.channel;
|
||||
if (!change) return;
|
||||
|
||||
// Extract channel data
|
||||
const channels = state.guild.channels;
|
||||
try {
|
||||
// Create private channel with all permissions
|
||||
const chName = `${name}${name.endsWith('s') ? "'" : "'s"} channel`;
|
||||
const privCh = await channels.create({
|
||||
name: chName,
|
||||
type: ChannelType.GuildVoice,
|
||||
permissionOverwrites: [
|
||||
{
|
||||
id: member.id,
|
||||
allow: [
|
||||
PermissionsBitField.All
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
const guild = newState.guild.name;
|
||||
const member = newState.member.user.username;
|
||||
const state = newState.channel ? 'joined' : 'left';
|
||||
const channel = (oldState.channel ?? newState.channel).name;
|
||||
|
||||
// Move user to private channel
|
||||
await state.setChannel(privCh);
|
||||
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.');
|
||||
}
|
||||
console.debug(`[DEBUG] User '${member}' ${state} channel '${channel}' in guild '${guild}'.`);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user