const { SlashCommandBuilder, PermissionFlagsBits, ChannelType, EmbedBuilder, MessageFlags } = require("discord.js"); module.exports = { data: new SlashCommandBuilder() .setName("ticket") .setDescription("Ticket system commands") .addSubcommand(sub => sub .setName("open") .setDescription("Open a support ticket") ) .addSubcommand(sub => sub .setName("close") .setDescription("Close the current ticket") ), async execute(interaction) { const sub = interaction.options.getSubcommand(); // === /ticket open === if (sub === "open") { const existing = interaction.guild.channels.cache.find( c => c.name === `ticket-${interaction.user.id}` ); if (existing) { return interaction.reply({ content: `❌ You already have an open ticket: ${existing}`, flags: MessageFlags.Ephemeral }); } const ticketChannel = await interaction.guild.channels.create({ name: `ticket-${interaction.user.id}`, type: ChannelType.GuildText, permissionOverwrites: [ { id: interaction.guild.id, deny: [PermissionFlagsBits.ViewChannel] }, { id: interaction.user.id, allow: [ PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages, PermissionFlagsBits.ReadMessageHistory ] }, { id: interaction.guild.roles.everyone, deny: [PermissionFlagsBits.ViewChannel] } ] }); const embed = new EmbedBuilder() .setColor("Blue") .setTitle("🎟️ New Ticket Opened") .setDescription( `Hello ${interaction.user}, a staff member will be with you shortly.\n\nUse \`/ticket close\` when your issue is resolved.` ) .setTimestamp(); await ticketChannel.send({ content: `<@&STAFF_ROLE_ID>`, embeds: [embed] }); await interaction.reply({ content: `✅ Your ticket has been created: ${ticketChannel}`, flags: MessageFlags.Ephemeral }); } // === /ticket close === else if (sub === "close") { if (!interaction.channel.name.startsWith("ticket-")) { return interaction.reply({ content: "❌ This is not a ticket channel.", flags: MessageFlags.Ephemeral }); } await interaction.reply("🛑 Closing ticket in 5 seconds..."); setTimeout(() => { interaction.channel.delete().catch(() => {}); }, 5000); } } };