const { ActionRowBuilder, EmbedBuilder, ButtonBuilder, WebhookClient, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js'); const transcripts = require('discord-html-transcripts'); module.exports = { data: { name: 'closeticket', }, async execute(interaction, client, args) { const webhook = new WebhookClient({ url: client.config.webhook.tickets }); if (!interaction.member.roles.cache.has(client.config.lf.staffRoleId)) { return interaction.reply({ content: 'Only staff can use this', ephemeral: true, }); } const modal = new ModalBuilder() .setCustomId('closetickets') .setTitle('Ticket close form') .addComponents( new ActionRowBuilder() .addComponents( new TextInputBuilder() .setCustomId('reason') .setLabel('Why do you want to close the ticket?') .setStyle(TextInputStyle.Paragraph) ) ) await interaction.showModal(modal); const submitted = await interaction.awaitModalSubmit({ time: 60000, filter: (i) => i.user.id === interaction.user.id, }).catch((err) => { return null }); if (submitted) { const reason = submitted.fields.getTextInputValue('reason'); const channel = submitted.channel; const ownerTicket = submitted.guild.members.cache.get(args[0]); const attachment = await transcripts.createTranscript(channel, { saveImages: true }); await submitted.update({ components: [ new ActionRowBuilder() .addComponents( submitted.message.components[0].components.map((x, i) => { return ButtonBuilder.from(submitted.message.components[0].components[i]).setDisabled(true); }) ) ] }); await submitted.followUp({ content: 'The ticket has entered the closing process correctly!', ephemeral: true, }); await submitted.channel.send({ embeds: [ new EmbedBuilder() .setColor('#701196') .setDescription('The ticket will be closed in 5 seconds...') ] }); setTimeout(async function() { if (submitted.channel !== null) { await submitted.channel.delete().catch((err) => { return null }); } return null; }, 5000); return await webhook.send({ content: '<:Empty:1286828514770812948>', embeds: [ new EmbedBuilder() .setColor('#701196') .setDescription(`# 📝 Transcript`) .setTimestamp() .addFields( { name: 'Ticket', value: `#${channel.name} (${channel.id})` }, { name: 'Panel', value: `${channel.name.split('-')[0].charAt(0).toUpperCase() + channel.name.split('-')[0].slice(1)}` }, { name: 'Owner', value: `**[@${ownerTicket.user.username}]()** (${ownerTicket.user.id})\n<:Vacio:1286828514770812948>` }, { name: 'Moderator', value: `**[@${submitted.user.username}]()** (${submitted.user.id})` }, { name: 'Reason', value: `${reason}` }, ) ], files: [attachment] }).catch((err) => { return null }); } } }