const { ticket_settings } = require("../config"); const { query } = require("../helpers/helper"); const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, ButtonBuilder, ActionRowBuilder } = require("discord.js"); module.exports = { data: new SlashCommandBuilder() .setName("send-ticket-message") .setDescription("Send a ticket message") .addStringOption(option => option .setRequired(false) .setName("description") .setDescription("Enter a description.") ) .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), async run(interaction) { let { options } = interaction; const deferOptions = { ephemeral: true }; await interaction.deferReply(deferOptions); let description = options.getString("description"); while (description?.includes('[E]')) { description = description.replace("[E]", "\n"); } let ticketEmbed = new EmbedBuilder() .setColor(ticket_settings.embed_color) .setThumbnail(ticket_settings.ticket_thumbnail) .setDescription("Please use /settings commands first!"); let settings = await query(db, `SELECT * FROM settings WHERE guildID='${interaction.guildId}'`); const noSettingsReply = { embeds: [ticketEmbed], ephemeral: true }; if (!settings) { return interaction.editReply(noSettingsReply); } const authorText = { name: "Ticket Support:" }; ticketEmbed.setAuthor(authorText); ticketEmbed.setDescription(description || "Click the button below to create a ticket!"); let createButton = new ButtonBuilder() .setEmoji(ticket_settings.buttoncreateemoji) .setLabel(ticket_settings.buttoncreatelabel) .setStyle(ticket_settings.buttoncreatestyle) .setCustomId("create_ticket"); let actionRow = new ActionRowBuilder().addComponents(createButton); const ticketMessage = { embeds: [ticketEmbed], components: [actionRow] }; await interaction.channel.send(ticketMessage); return interaction.deleteReply(); } };