import { SlashCommandBuilder, PermissionFlagsBits, ChatInputCommandInteraction, ChannelType } from 'discord.js'; import { prisma } from '../database'; import { ErrorCodes, createBotError } from '../errors/ErrorCodes'; export default { data: new SlashCommandBuilder() .setName('voice-setup') .setDescription('Setup a generator voice channel for temporary channels.') .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) .addSubcommand(subcommand => subcommand .setName('set') .setDescription('Set an existing voice channel as a Generator') .addChannelOption(option => option.setName('channel') .setDescription('The voice channel to act as the Generator') .setRequired(true) .addChannelTypes(ChannelType.GuildVoice) ) .addChannelOption(option => option.setName('category') .setDescription('(Optional) The category where temp channels will be created') .setRequired(false) .addChannelTypes(ChannelType.GuildCategory) ) ) .addSubcommand(subcommand => subcommand .setName('create') .setDescription('Create a new voice channel and set it as a Generator') .addStringOption(option => option.setName('name') .setDescription('The name of the new generator voice channel') .setRequired(true) ) .addChannelOption(option => option.setName('category') .setDescription('(Optional) The category where the new channel will be created') .setRequired(false) .addChannelTypes(ChannelType.GuildCategory) ) ), async execute(interaction: ChatInputCommandInteraction) { const subcommand = interaction.options.getSubcommand(); const category = interaction.options.getChannel('category'); if (subcommand === 'set') { const channel = interaction.options.getChannel('channel', true); await prisma.voiceGenerator.upsert({ where: { channelId: channel.id }, update: { categoryId: category?.id || null, guildId: interaction.guildId! }, create: { channelId: channel.id, guildId: interaction.guildId!, categoryId: category?.id || null, } }); await interaction.reply({ content: `Successfully set up ${channel} as a Voice Generator Channel!`, ephemeral: true }); } else if (subcommand === 'create') { const name = interaction.options.getString('name', true); const guild = interaction.guild!; const newChannel = await guild.channels.create({ name: name, type: ChannelType.GuildVoice, parent: category?.id || null, }); await prisma.voiceGenerator.create({ data: { channelId: newChannel.id, guildId: guild.id, categoryId: category?.id || null, } }); await interaction.reply({ content: `Successfully created and set up ${newChannel} as a Voice Generator Channel!`, ephemeral: true }); } }, };