Stryker-SC/Discord-Bot-VCMaster-JavaScript-Revamped
0
1const { SlashCommandBuilder, PermissionFlagsBits, ChannelType, MessageFlags } = require('discord.js');2 3module.exports = {4 data: new SlashCommandBuilder()5 .setName('setup-voice')6 .setDescription('Set the "Join to Create" hub channel.')7 .addChannelOption(option =>8 option.setName('channel')9 .setDescription('The voice channel to act as the Hub')10 .addChannelTypes(ChannelType.GuildVoice)11 .setRequired(true))12 .addChannelOption(option =>13 option.setName('category')14 .setDescription('The category to create temp channels in')15 .addChannelTypes(ChannelType.GuildCategory)16 .setRequired(false))17 .setDefaultMemberPermissions(PermissionFlagsBits.Administrator),18 19 async execute(interaction, client) {20 await interaction.deferReply({ ephemeral: true });21 22 const channel = interaction.options.getChannel('channel');23 const category = interaction.options.getChannel('category');24 25 try {26 // Permission check: Verify bot has required permissions27 const botMember = interaction.guild.members.me;28 29 const checkPermissions = (targetChannel) => {30 const missing = [];31 const perms = botMember.permissionsIn(targetChannel);32 if (!perms.has(PermissionFlagsBits.ManageChannels)) missing.push('Manage Channels');33 if (!perms.has(PermissionFlagsBits.MoveMembers)) missing.push('Move Members');34 if (!perms.has(PermissionFlagsBits.Connect)) missing.push('Connect');35 return missing;36 };37 38 const missingInChannel = checkPermissions(channel);39 if (missingInChannel.length > 0) {40 return interaction.editReply({ 41 content: `❌ I am missing the following permissions in the **${channel.name}** channel:\n- ${missingInChannel.join('\n- ')}` 42 });43 }44 45 if (category) {46 const missingInCategory = checkPermissions(category);47 if (missingInCategory.length > 0) {48 return interaction.editReply({ 49 content: `❌ I am missing the following permissions in the **${category.name}** category:\n- ${missingInCategory.join('\n- ')}` 50 });51 }52 }53 54 await client.db.setHubChannel(interaction.guild.id, channel.id, category ? category.id : null);55 56 let reply = `✅ **Setup Complete!**\nHub Channel: ${channel}\n`;57 if (category) {58 reply += `Target Category: ${category}`;59 } else {60 reply += `Target Category: Same as Hub Channel`;61 }62 63 await interaction.editReply({ content: reply });64 } catch (error) {65 console.error(error);66 await interaction.editReply({ content: '❌ An error occurred while saving the configuration.' });67 }68 },69};70 