diff options
| author | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-07-22 15:32:57 +0100 |
|---|---|---|
| committer | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-07-22 15:32:57 +0100 |
| commit | 72487019b3f255cece40a8073bbad8bc9968a3b7 (patch) | |
| tree | b6590e63039cdc8b1820bd345cdfe83f28ff839b /174bg/discord-bot/source/commands/close-ticket.js | |
| parent | da0509c91376f56f133872eddd2e4282d76f215e (diff) | |
| download | unnamed-group-72487019b3f255cece40a8073bbad8bc9968a3b7.tar unnamed-group-72487019b3f255cece40a8073bbad8bc9968a3b7.tar.gz unnamed-group-72487019b3f255cece40a8073bbad8bc9968a3b7.tar.bz2 unnamed-group-72487019b3f255cece40a8073bbad8bc9968a3b7.tar.xz unnamed-group-72487019b3f255cece40a8073bbad8bc9968a3b7.zip | |
major code refactor, add uex lookup
Diffstat (limited to '174bg/discord-bot/source/commands/close-ticket.js')
| -rw-r--r-- | 174bg/discord-bot/source/commands/close-ticket.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/174bg/discord-bot/source/commands/close-ticket.js b/174bg/discord-bot/source/commands/close-ticket.js new file mode 100644 index 0000000..ca3040e --- /dev/null +++ b/174bg/discord-bot/source/commands/close-ticket.js @@ -0,0 +1,55 @@ +import { SlashCommandBuilder, PermissionFlagsBits } from "discord.js"; + +export default { + data: new SlashCommandBuilder() + .setName("close-ticket") + .setDescription( + "Closes the current ticket by logging the contents and deleting the channel.", + ) + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), + execute: async (interaction) => { + const channel = interaction.channel; + + if (!channel || !channel.name.startsWith("ticket-")) { + return await interaction.reply({ + content: "This command can only be used in a ticket channel.", + ephemeral: true, + }); + } + + // log the contents of the ticket and send to the logs channel if it exists + const messages = await channel.messages.fetch({ limit: 100 }); + const log = messages + .map((message) => `${message.author.tag}: ${message.content}`) + .reverse() + .join("\n"); + + console.log(`Ticket log for ${channel.name}:\n${log}`); + + const logsChannel = interaction.guild.channels.cache.find( + (ch) => ch.name === "logs" && ch.isTextBased(), + ); + + if (logsChannel) + await logsChannel.send({ + content: `# Ticket log for ${channel.name}`, + files: [ + { + name: `${channel.name}.txt`, + attachment: Buffer.from( + messages + .map( + (message) => + `${message.author.tag}/${message.author.id}: ${message.content}`, + ) + .reverse() + .join("\n"), + ), + }, + ], + }); + + // delete the channel + await channel.delete(); + }, +}; |
