generated from Baipyrus/DiscordJS-Template
basic custom vc slash command
This commit is contained in:
parent
b5079b6f40
commit
d0ec7fbb6c
@ -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,14 +28,47 @@ export const data = new SlashCommandBuilder()
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
export async function execute(interaction) {
|
export async function execute(interaction) {
|
||||||
const { options } = interaction;
|
const { guild, options } = interaction;
|
||||||
|
|
||||||
switch (options.getSubcommand()) {
|
let step;
|
||||||
case 'create':
|
try {
|
||||||
const name = options.getString('name');
|
switch (options.getSubcommand()) {
|
||||||
break;
|
case 'create': {
|
||||||
case 'register':
|
// Get channel name from user input
|
||||||
const id = options.getString('id');
|
const name = options.getString('name');
|
||||||
break;
|
|
||||||
|
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
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user