import { ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, PermissionFlagsBits } from 'discord.js'; import { readFile } from 'fs/promises'; export default { async handleInteraction(interaction) { if (interaction.isButton()) { if (interaction.customId === 'rename') { const modal = new ModalBuilder() .setCustomId('modal_changename') .setTitle('Change VC Name') .addComponents( new ActionRowBuilder().addComponents( new TextInputBuilder() .setCustomId('_value') .setLabel('New VC Name') .setStyle(TextInputStyle.Short) .setPlaceholder('Enter new name') .setRequired(true) ) ); return await interaction.showModal(modal); } if (interaction.customId === 'group') { const modal = new ModalBuilder() .setCustomId('modal_limit') .setTitle('Set VC User Limit') .addComponents( new ActionRowBuilder().addComponents( new TextInputBuilder() .setCustomId('_value') .setLabel('Max Users (0 = unlimited)') .setStyle(TextInputStyle.Short) .setPlaceholder('0 - 99') .setRequired(true) ) ); return await interaction.showModal(modal); } let tempVCUsers; try { const jsonString = await readFile('./database/tempvcusers.json', 'utf8'); tempVCUsers = JSON.parse(jsonString); } catch { return interaction.reply({ content: "❌ Could not load temporary VC user data.", ephemeral: true }); } const userId = interaction.user.id; const tempData = tempVCUsers[userId]; if (!tempData || !tempData.channelId) { return interaction.reply({ content: "❌ You don't own a temporary voice channel.", ephemeral: true }); } const VC = interaction.guild.channels.cache.get(tempData.channelId); if (!VC) { return interaction.reply({ content: "❌ VC not found or already deleted.", ephemeral: true }); } if (interaction.customId === 'lock') { try { await VC.permissionOverwrites.edit(interaction.guild.roles.everyone, { [PermissionFlagsBits.Connect]: false, }); return interaction.reply({ content: "🔒 Your VC has been locked.", ephemeral: true }); } catch (err) { return interaction.reply({ content: `❌ Failed to lock: ${err}`, ephemeral: true }); } } if (interaction.customId === 'unlock') { try { await VC.permissionOverwrites.edit(interaction.guild.roles.everyone, { [PermissionFlagsBits.Connect]: true, }); return interaction.reply({ content: "🔓 Your VC has been unlocked.", ephemeral: true }); } catch (err) { return interaction.reply({ content: `❌ Failed to unlock: ${err}`, ephemeral: true }); } } } if (interaction.isModalSubmit()) { let tempVCUsers; try { const jsonString = await readFile('./database/tempvcusers.json', 'utf8'); tempVCUsers = JSON.parse(jsonString); } catch { return interaction.reply({ content: "❌ Could not load temporary VC user data.", ephemeral: true }); } const userId = interaction.user.id; const tempData = tempVCUsers[userId]; if (!tempData || !tempData.channelId) { return interaction.reply({ content: "❌ You don't own a temporary voice channel.", ephemeral: true }); } const VC = interaction.guild.channels.cache.get(tempData.channelId); if (!VC) { return interaction.reply({ content: "❌ VC not found or already deleted.", ephemeral: true }); } if (interaction.customId === 'modal_limit') { let inputnum = interaction.fields.getTextInputValue('_value'); const numValue = Number(inputnum); if (isNaN(numValue) || numValue > 99 || numValue < 0) { return interaction.reply({ content: "Please enter a value between 0 and 99.", ephemeral: true }).catch(() => { if (VC) VC.send("Unknown Error. Please try again."); }); } try { await VC.setUserLimit(numValue); return interaction.reply({ content: `OK. The UserLimit is set to ${numValue}.`, ephemeral: true }); } catch (err) { return interaction.reply({ content: `Something is wrong. Please try again.\nError: \`\`\`${err}\`\`\``, ephemeral: true }).catch(() => { if (VC) VC.send(`Something is wrong. Please try again.\nError: \`\`\`${err}\`\`\``); }); } } if (interaction.customId === 'modal_changename') { await interaction.deferReply({ ephemeral: true }); let inputstr = interaction.fields.getTextInputValue('_value'); try { await VC.setName(inputstr); return interaction.editReply({ content: `OK. VC name is set to ${inputstr}.`, ephemeral: true }); } catch (err) { return interaction.editReply({ content: `Something is wrong. Please try again.\nError: \`\`\`${err}\`\`\``, ephemeral: true }).catch(() => { if (VC) VC.send(`Something is wrong. Please try again.\nError: \`\`\`${err}\`\`\``); }); } } } } };