generated from Baipyrus/DiscordJS-Template
Compare commits
4 Commits
c8e3fc2f2c
...
d0ec7fbb6c
Author | SHA1 | Date | |
---|---|---|---|
d0ec7fbb6c | |||
b5079b6f40 | |||
1a3e7ac96b | |||
a0eb75e4ee |
@ -1,4 +1,5 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
|
import { VoiceChannel } from '../../../database.js';
|
||||||
|
|
||||||
export const data = new SlashCommandBuilder()
|
export const data = new SlashCommandBuilder()
|
||||||
.setName('custom_vc')
|
.setName('custom_vc')
|
||||||
@ -27,6 +28,47 @@ export const data = new SlashCommandBuilder()
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
export async function execute(interaction) {
|
export async function execute(interaction) {
|
||||||
const { options } = interaction;
|
const { guild, options } = interaction;
|
||||||
// const id = options.getString('id');
|
|
||||||
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,36 @@
|
|||||||
import { Events } from 'discord.js';
|
import { ChannelType, Events, PermissionsBitField } 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;
|
// Extract user data
|
||||||
if (!change) return;
|
const member = state.member;
|
||||||
|
const name = member.user.username;
|
||||||
|
|
||||||
const guild = newState.guild.name;
|
// Extract channel data
|
||||||
const member = newState.member.user.username;
|
const channels = state.guild.channels;
|
||||||
const state = newState.channel ? 'joined' : 'left';
|
try {
|
||||||
const channel = (oldState.channel ?? newState.channel).name;
|
// 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
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
console.debug(`[DEBUG] User '${member}' ${state} channel '${channel}' in guild '${guild}'.`);
|
// 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.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user