Tickets! and a lot of bug fixes
diff --git a/src/actions/tickets/create.ts b/src/actions/tickets/create.ts
index 595a5b3..3c2dd2c 100644
--- a/src/actions/tickets/create.ts
+++ b/src/actions/tickets/create.ts
@@ -3,16 +3,16 @@
 import client from "../../utils/client.js";
 import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
 import getEmojiByName from "../../utils/getEmojiByName.js";
+import { getCommandMentionByName } from "../../utils/getCommandMentionByName.js";
 
 function capitalize(s: string) {
     s = s.replace(/([A-Z])/g, " $1");
-    return s.length < 3 ? s.toUpperCase() : s[0].toUpperCase() + s.slice(1).toLowerCase();
+    return s.length < 3 ? s.toUpperCase() : s[0]!.toUpperCase() + s.slice(1).toLowerCase();
 }
 
 export default async function (interaction: CommandInteraction | ButtonInteraction) {
     if (!interaction.guild) return;
     const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger;
-
     const config = await client.database.guilds.read(interaction.guild.id);
     if (!config.tickets.enabled || !config.tickets.category) {
         return await interaction.reply({
@@ -21,7 +21,7 @@
                     .setTitle("Tickets are disabled")
                     .setDescription("Please enable tickets in the configuration to use this command.")
                     .setFooter({
-                        text: interaction.member.permissions.has("MANAGE_GUILD")
+                        text: (interaction.member!.permissions as Discord.PermissionsBitField).has("ManageGuild")
                             ? "You can enable it by running /settings tickets"
                             : ""
                     })
@@ -31,16 +31,26 @@
             ephemeral: true
         });
     }
-    const category = interaction.guild.channels.cache.get(config.tickets.category) as Discord.CategoryChannel;
     let count = 0;
-    category.children.forEach((element) => {
-        if (!(element.type === "GUILD_TEXT")) return;
-        if ((element as Discord.TextChannel).topic.includes(`${interaction.member.user.id}`)) {
-            if ((element as Discord.TextChannel).topic.endsWith("Active")) {
-                count++;
+    const targetChannel: Discord.CategoryChannel | Discord.TextChannel = (await interaction.guild.channels.fetch(config.tickets.category))! as Discord.CategoryChannel | Discord.TextChannel;
+    if (targetChannel.type === Discord.ChannelType.GuildCategory) {
+        // For channels, the topic is the user ID, then the word Active
+        const category = targetChannel as Discord.CategoryChannel;
+        category.children.cache.forEach((element) => {
+            if (!(element.type === Discord.ChannelType.GuildText)) return;
+            if (((element as Discord.TextChannel).topic ?? "").includes(`${interaction.member!.user.id}`)) {
+                if (((element as Discord.TextChannel).topic ?? "").endsWith("Active")) { count++; }
             }
-        }
-    });
+        });
+    } else {
+        // For threads, the name is the users name, id, then the word Active
+        const channel = targetChannel as Discord.TextChannel;
+        channel.threads.cache.forEach((element: Discord.ThreadChannel) => {
+            if (element.name.includes(`${interaction.member!.user.id}`)) {
+                if (element.name.endsWith("Active")) { count++; }
+            }
+        });
+    }
     if (count >= config.tickets.maxTickets) {
         return await interaction.reply({
             embeds: [
@@ -55,15 +65,15 @@
             ephemeral: true
         });
     }
-    let ticketTypes;
+    let ticketTypes: string[];
     let custom = false;
     if (config.tickets.customTypes && config.tickets.useCustom) {
         ticketTypes = config.tickets.customTypes;
         custom = true;
     } else if (config.tickets.types) ticketTypes = toHexArray(config.tickets.types, tickets);
     else ticketTypes = [];
-    let chosenType;
-    let splitFormattedTicketTypes = [];
+    let chosenType: string | null;
+    let splitFormattedTicketTypes: ActionRowBuilder<ButtonBuilder>[] = [];
     if (ticketTypes.length > 0) {
         let formattedTicketTypes = [];
         formattedTicketTypes = ticketTypes.map((type) => {
@@ -78,7 +88,7 @@
             }
         });
         for (let i = 0; i < formattedTicketTypes.length; i += 5) {
-            splitFormattedTicketTypes.push(new ActionRowBuilder().addComponents(formattedTicketTypes.slice(i, i + 5)));
+            splitFormattedTicketTypes.push(new ActionRowBuilder<ButtonBuilder>().addComponents(formattedTicketTypes.slice(i, i + 5)));
         }
         const m = await interaction.reply({
             embeds: [
@@ -94,7 +104,10 @@
         });
         let component;
         try {
-            component = await m.awaitMessageComponent({ time: 300000 });
+            component = await m.awaitMessageComponent({
+                time: 300000,
+                filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id }
+            });
         } catch (e) {
             return;
         }
@@ -118,7 +131,7 @@
             }
         });
         for (let i = 0; i < formattedTicketTypes.length; i += 5) {
-            splitFormattedTicketTypes.push(new ActionRowBuilder().addComponents(formattedTicketTypes.slice(i, i + 5)));
+            splitFormattedTicketTypes.push(new ActionRowBuilder<ButtonBuilder>().addComponents(formattedTicketTypes.slice(i, i + 5)));
         }
         component.update({
             embeds: [
@@ -138,107 +151,190 @@
             components: splitFormattedTicketTypes
         });
     }
-    const overwrites = [
-        {
-            id: interaction.member,
-            allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
-            type: "member"
-        }
-    ] as Discord.OverwriteResolvable[];
-    overwrites.push({
-        id: interaction.guild.roles.everyone,
-        deny: ["VIEW_CHANNEL"],
-        type: "role"
-    });
-    if (config.tickets.supportRole !== null) {
+    let c: Discord.TextChannel | Discord.PrivateThreadChannel;
+    if (targetChannel.type === Discord.ChannelType.GuildCategory) {
+        const overwrites = [
+            {
+                id: interaction.member,
+                allow: ["ViewChannel", "SendMessages", "AttachFiles", "AddReactions", "ReadMessageHistory"],
+                type: Discord.OverwriteType.Member
+            }
+        ] as Discord.OverwriteResolvable[];
         overwrites.push({
-            id: interaction.guild.roles.cache.get(config.tickets.supportRole),
-            allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
-            type: "role"
+            id: interaction.guild.roles.everyone,
+            deny: ["ViewChannel"],
+            type: Discord.OverwriteType.Role
         });
-    }
+        if (config.tickets.supportRole !== null) {
+            overwrites.push({
+                id: interaction.guild.roles.cache.get(config.tickets.supportRole)!,
+                allow: ["ViewChannel", "SendMessages", "AttachFiles", "AddReactions", "ReadMessageHistory"],
+                type: Discord.OverwriteType.Role
+            });
+        }
 
-    let c;
-    try {
-        c = await interaction.guild.channels.create(interaction.member.user.username, {
-            type: "GUILD_TEXT",
-            topic: `${interaction.member.user.id} Active`,
-            parent: config.tickets.category,
-            nsfw: false,
-            permissionOverwrites: overwrites as Discord.OverwriteResolvable[],
-            reason: "Creating ticket"
-        });
-    } catch (e) {
-        return await interaction.editReply({
-            embeds: [
-                new EmojiEmbed()
-                    .setTitle("Create Ticket")
-                    .setDescription("Failed to create ticket")
-                    .setStatus("Danger")
-                    .setEmoji("CONTROL.BLOCKCROSS")
-            ]
-        });
-    }
-    try {
-        await c.send({
-            content:
-                `<@${interaction.member.user.id}>` +
-                (config.tickets.supportRole !== null ? ` • <@&${config.tickets.supportRole}>` : ""),
-            allowedMentions: {
-                users: [(interaction.member as Discord.GuildMember).id],
-                roles: config.tickets.supportRole !== null ? [config.tickets.supportRole] : []
+        try {
+            c = await interaction.guild.channels.create({
+                name: `${interaction.member!.user.username.toLowerCase()}`,
+                type: Discord.ChannelType.GuildText,
+                topic: `${interaction.member!.user.id} Active`,
+                parent: config.tickets.category,
+                nsfw: false,
+                permissionOverwrites: overwrites as Discord.OverwriteResolvable[],
+                reason: "Creating ticket"
+            });
+        } catch (e) {
+            return await interaction.editReply({
+                embeds: [
+                    new EmojiEmbed()
+                        .setTitle("Create Ticket")
+                        .setDescription("Failed to create ticket")
+                        .setStatus("Danger")
+                        .setEmoji("CONTROL.BLOCKCROSS")
+                ]
+            });
+        }
+        try {
+            await c.send({
+                content:
+                    `<@${interaction.member!.user.id}>` +
+                    (config.tickets.supportRole !== null ? ` • <@&${config.tickets.supportRole}>` : ""),
+                allowedMentions: {
+                    users: [(interaction.member as Discord.GuildMember).id],
+                    roles: config.tickets.supportRole !== null ? [config.tickets.supportRole] : []
+                }
+            });
+            let content: string | null = null;
+            if (interaction.isCommand()) {
+                content = interaction.options.get("message")?.value as string;
             }
-        });
-        let content = interaction.options ? interaction.options.getString("message") || "" : "";
-        if (content) content = `**Message:**\n> ${content}\n`;
-        const emoji = custom ? "" : getEmojiByName("TICKETS." + chosenType.toUpperCase());
-        await c.send({
-            embeds: [
-                new EmojiEmbed()
-                    .setTitle("New Ticket")
-                    .setDescription(
-                        `Ticket created by <@${interaction.member.user.id}>\n` +
-                            `**Support type:** ${
-                                chosenType !== null ? emoji + " " + capitalize(chosenType) : "General"
-                            }\n` +
-                            `**Ticket ID:** \`${c.id}\`\n${content}\n` +
-                            "Type `/ticket close` to close this ticket."
-                    )
-                    .setStatus("Success")
-                    .setEmoji("GUILD.TICKET.OPEN")
-            ],
-            components: [
-                new ActionRowBuilder().addComponents([
-                    new ButtonBuilder()
-                        .setLabel("Close")
-                        .setStyle(ButtonStyle.Danger)
-                        .setCustomId("closeticket")
-                        .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
-                ])
-            ]
-        });
-        const data = {
-            meta: {
-                type: "ticketCreate",
-                displayName: "Ticket Created",
-                calculateType: "ticketUpdate",
-                color: NucleusColors.green,
-                emoji: "GUILD.TICKET.OPEN",
-                timestamp: new Date().getTime()
-            },
-            list: {
-                ticketFor: entry(interaction.member.user.id, renderUser(interaction.member.user)),
-                created: entry(new Date().getTime(), renderDelta(new Date().getTime())),
-                ticketChannel: entry(c.id, renderChannel(c))
-            },
-            hidden: {
-                guild: interaction.guild.id
+            if (content) content = `**Message:**\n> ${content}\n`;
+            let emoji;
+            if (chosenType) {
+                emoji = custom ? "" : getEmojiByName("TICKETS." + chosenType.toUpperCase());
+            } else {
+                emoji = "";
             }
-        };
-        log(data);
-    } catch (e) {
-        console.log(e);
+            await c.send({
+                embeds: [
+                    new EmojiEmbed()
+                        .setTitle("New Ticket")
+                        .setDescription(
+                            `Ticket created by <@${interaction.member!.user.id}>\n` +
+                                `**Support type:** ${
+                                    chosenType !== null ? emoji + " " + capitalize(chosenType) : "General"
+                                }\n` +
+                                `**Ticket ID:** \`${c.id}\`\n${content ?? ""}\n` +
+                                `Type ${await getCommandMentionByName("ticket/close")} to close this ticket.`
+                        )
+                        .setStatus("Success")
+                        .setEmoji("GUILD.TICKET.OPEN")
+                ],
+                components: [
+                    new ActionRowBuilder<ButtonBuilder>().addComponents([
+                        new ButtonBuilder()
+                            .setLabel("Close")
+                            .setStyle(ButtonStyle.Danger)
+                            .setCustomId("closeticket")
+                            .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+                    ])
+                ]
+            });
+        } catch (e) {
+            return await interaction.editReply({
+                embeds: [
+                    new EmojiEmbed()
+                        .setTitle("Create Ticket")
+                        .setDescription("Failed to create ticket")
+                        .setStatus("Danger")
+                        .setEmoji("GUILD.TICKET.CLOSE")
+                ]
+            });
+        }
+    } else {
+        c = await targetChannel.threads.create({name: `${interaction.member!.user.username} - ${interaction.member!.user.id} - Active`,
+                                                autoArchiveDuration: 60 * 24 * 7,
+                                                type: Discord.ChannelType.PrivateThread,
+                                                reason: "Creating ticket"
+                                                }) as Discord.PrivateThreadChannel;
+        c.members.add(interaction.member!.user.id);  // TODO: When a thread is used, and a support role is added, automatically set channel permissions
+        try {
+            await c.send({
+                content:
+                    `<@${interaction.member!.user.id}>` +
+                    (config.tickets.supportRole !== null ? ` • <@&${config.tickets.supportRole}>` : ""),
+                allowedMentions: {
+                    users: [(interaction.member as Discord.GuildMember).id],
+                    roles: config.tickets.supportRole !== null ? [config.tickets.supportRole] : []
+                }
+            });
+            let content: string | null = null;
+            if (interaction.isCommand()) {
+                content = interaction.options.get("message")?.value as string;
+            }
+            if (content) content = `**Message:**\n> ${content}\n`;
+            let emoji;
+            if (chosenType) {
+                emoji = custom ? "" : getEmojiByName("TICKETS." + chosenType.toUpperCase());
+            } else {
+                emoji = "";
+            }
+            await c.send({
+                embeds: [
+                    new EmojiEmbed()
+                        .setTitle("New Ticket")
+                        .setDescription(
+                            `Ticket created by <@${interaction.member!.user.id}>\n` +
+                                `**Support type:** ${
+                                    chosenType !== null ? emoji + " " + capitalize(chosenType) : "General"
+                                }\n` +
+                                `**Ticket ID:** \`${c.id}\`\n${content ?? ""}\n` +
+                                `Type ${await getCommandMentionByName("ticket/close")} to close this ticket.`
+                        )
+                        .setStatus("Success")
+                        .setEmoji("GUILD.TICKET.OPEN")
+                ],
+                components: [
+                    new ActionRowBuilder<ButtonBuilder>().addComponents([
+                        new ButtonBuilder()
+                            .setLabel("Close")
+                            .setStyle(ButtonStyle.Danger)
+                            .setCustomId("closeticket")
+                            .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+                    ])
+                ]
+            });
+        } catch (e) {
+            return await interaction.editReply({
+                embeds: [
+                    new EmojiEmbed()
+                        .setTitle("Create Ticket")
+                        .setDescription("Failed to create ticket")
+                        .setStatus("Danger")
+                        .setEmoji("GUILD.TICKET.CLOSE")
+                ]
+            });
+        }
     }
+    const data = {
+        meta: {
+            type: "ticketCreate",
+            displayName: "Ticket Created",
+            calculateType: "ticketUpdate",
+            color: NucleusColors.green,
+            emoji: "GUILD.TICKET.OPEN",
+            timestamp: new Date().getTime()
+        },
+        list: {
+            ticketFor: entry(interaction.member!.user.id, renderUser(interaction.member!.user! as Discord.User)),
+            created: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+            ticketChannel: entry(c.id, renderChannel(c))
+        },
+        hidden: {
+            guild: interaction.guild.id
+        }
+    };
+    log(data);
     await interaction.editReply({
         embeds: [
             new EmojiEmbed()
diff --git a/src/actions/tickets/delete.ts b/src/actions/tickets/delete.ts
index cab38ec..48d2a51 100644
--- a/src/actions/tickets/delete.ts
+++ b/src/actions/tickets/delete.ts
@@ -1,50 +1,52 @@
-import Discord, { ButtonBuilder, ActionRowBuilder, ButtonStyle, ButtonInteraction } from "discord.js";
+import { getCommandMentionByName } from '../../utils/getCommandMentionByName.js';
+import Discord, { ActionRowBuilder, ButtonBuilder, ButtonInteraction, PrivateThreadChannel, TextChannel, ButtonStyle } from "discord.js";
 import client from "../../utils/client.js";
 import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
 import getEmojiByName from "../../utils/getEmojiByName.js";
+import { preloadPage } from '../../utils/createTemporaryStorage.js';
 
 export default async function (interaction: Discord.CommandInteraction | ButtonInteraction) {
     if (!interaction.guild) return;
+    const config = await client.database.guilds.read(interaction.guild.id);
     const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger;
 
-    const config = await client.database.guilds.read(interaction.guild.id);
-    let thread = false;
-    if (interaction.channel instanceof Discord.ThreadChannel) thread = true;
-    const threadChannel = interaction.channel as Discord.ThreadChannel;
-    const channel = interaction.channel as Discord.TextChannel;
-    if (
-        !channel.parent ||
-        config.tickets.category !== channel.parent.id ||
-        (thread ? threadChannel.parent.parent.id !== config.tickets.category : false)
-    ) {
-        return interaction.reply({
+    const ticketChannel = config.tickets.category;
+    if (!("parent" in interaction.channel!)) {
+        return await interaction.reply({
             embeds: [
                 new EmojiEmbed()
-                    .setTitle("Deleting Ticket...")
-                    .setDescription(
-                        "This ticket is not in your tickets category, so cannot be deleted. You cannot run close in a thread."
-                    )
+                    .setTitle("Not a ticket")
+                    .setDescription("This channel isn't a ticket, so you can't delete it.")
                     .setStatus("Danger")
                     .setEmoji("CONTROL.BLOCKCROSS")
-            ],
-            ephemeral: true
+            ], ephemeral: true
         });
-    }
-    const status = channel.topic.split(" ")[1];
-    if (status === "Archived") {
-        await interaction.reply({
+    } else if (interaction.channel!.parent!.id !== ticketChannel) {
+        return await interaction.reply({
             embeds: [
                 new EmojiEmbed()
-                    .setTitle("Delete Ticket")
-                    .setDescription("Your ticket is being deleted...")
+                    .setTitle("Not a ticket")
+                    .setDescription("This channel isn't a ticket, so you can't delete it.")
                     .setStatus("Danger")
-                    .setEmoji("GUILD.TICKET.CLOSE")
-            ]
+                    .setEmoji("CONTROL.BLOCKCROSS")
+            ], ephemeral: true
         });
+    }
+    const channel: PrivateThreadChannel | TextChannel = interaction.channel as PrivateThreadChannel | TextChannel;
+    let status: string | null = ("topic" in interaction.channel) ? interaction.channel!.topic : interaction.channel.name;
+    status = status ?? "";
+    if (status.endsWith("Archived")) { status = "Archived"; }
+    else { status = "Active"; }
+
+    const uID = channel.type === Discord.ChannelType.PrivateThread ? channel.name.split(" - ")[1] : channel.topic!.split(" ")[0];
+
+    if (status === "Archived") {
+        // Delete the ticket
+
         const data = {
             meta: {
-                type: "ticketDeleted",
-                displayName: "Ticket Deleted",
+                type: "ticketClosed",
+                displayName: "Ticket Closed",
                 calculateType: "ticketUpdate",
                 color: NucleusColors.red,
                 emoji: "GUILD.TICKET.CLOSE",
@@ -52,85 +54,45 @@
             },
             list: {
                 ticketFor: entry(
-                    channel.topic.split(" ")[0],
-                    renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)
+                    uID!,
+                    renderUser((await interaction.guild.members.fetch(uID!)).user)
                 ),
-                deletedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
-                deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
+                closedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user as Discord.User)),
+                closed: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+                ticketChannel: entry(channel.id, channel.name)
             },
             hidden: {
                 guild: interaction.guild.id
             }
         };
         log(data);
-        interaction.channel.delete();
-        return;
+
+        await channel.delete();
     } else if (status === "Active") {
+        // Close the ticket
+
+        if (channel.isThread()) {
+            channel.setName(`${channel.name.replace("Active", "Archived")}`);
+            channel.members.remove(channel.name.split(" - ")[1]!);
+        } else {
+            channel.setTopic(`${(channel.topic ?? "").replace("Active", "Archived")}`);
+            if (!channel.topic!.includes("Archived")) { channel.setTopic("0 Archived"); }
+            await channel.permissionOverwrites.delete(channel.topic!.split(" ")[0]!);
+        }
+        preloadPage(interaction.channel.id, "privacy", "2")
         await interaction.reply({
             embeds: [
                 new EmojiEmbed()
-                    .setTitle("Close Ticket")
-                    .setDescription("Your ticket is being closed...")
-                    .setStatus("Warning")
-                    .setEmoji("GUILD.TICKET.ARCHIVED")
-            ]
-        });
-        const overwrites = [
-            {
-                id: channel.topic.split(" ")[0],
-                deny: ["VIEW_CHANNEL"],
-                type: "member"
-            },
-            {
-                id: interaction.guild.id,
-                deny: ["VIEW_CHANNEL"],
-                type: "role"
-            }
-        ] as Discord.OverwriteResolvable[];
-        if (config.tickets.supportRole !== null) {
-            overwrites.push({
-                id: interaction.guild.roles.cache.get(config.tickets.supportRole),
-                allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
-                type: "role"
-            });
-        }
-        channel.edit({ permissionOverwrites: overwrites });
-        channel.setTopic(`${channel.topic.split(" ")[0]} Archived`);
-        const data = {
-            meta: {
-                type: "ticketClosed",
-                displayName: "Ticket Closed",
-                calculateType: "ticketUpdate",
-                color: NucleusColors.yellow,
-                emoji: "GUILD.TICKET.ARCHIVED",
-                timestamp: new Date().getTime()
-            },
-            list: {
-                ticketFor: entry(
-                    channel.topic.split(" ")[0],
-                    renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)
-                ),
-                closedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
-                closed: entry(new Date().getTime(), renderDelta(new Date().getTime())),
-                ticketChannel: entry(channel.id, renderChannel(channel))
-            },
-            hidden: {
-                guild: interaction.guild.id
-            }
-        };
-        log(data);
-        await interaction.editReply({
-            embeds: [
-                new EmojiEmbed()
-                    .setTitle("Close Ticket")
-                    .setDescription(
-                        "This ticket has been closed.\nType `/ticket close` again to delete it.\n\nNote: Check `/privacy` for details about transcripts."
-                    )
+                    .setTitle("Archived Ticket")
+                    .setDescription(`This ticket has been Archived. Type ${await getCommandMentionByName("ticket/close")} to delete it.` +
+                        await client.database.premium.hasPremium(interaction.guild.id) ?
+                        `\n\nFor more info on transcripts, check ${await getCommandMentionByName("privacy")}` :
+                        "")
                     .setStatus("Warning")
                     .setEmoji("GUILD.TICKET.ARCHIVED")
             ],
             components: [
-                new ActionRowBuilder().addComponents(
+                new ActionRowBuilder<ButtonBuilder>().addComponents(
                     [
                         new ButtonBuilder()
                             .setLabel("Delete")
@@ -138,27 +100,52 @@
                             .setCustomId("closeticket")
                             .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
                     ].concat(
-                        client.database.premium.hasPremium(interaction.guild.id)
+                        await client.database.premium.hasPremium(interaction.guild.id)
                             ? [
-                                  new ButtonBuilder()
-                                      .setLabel("Create Transcript and Delete")
-                                      .setStyle(ButtonStyle.Primary)
-                                      .setCustomId("createtranscript")
-                                      .setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
-                              ]
+                                    new ButtonBuilder()
+                                        .setLabel("Create Transcript and Delete")
+                                        .setStyle(ButtonStyle.Primary)
+                                        .setCustomId("createtranscript")
+                                        .setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
+                                ]
                             : []
                     )
                 )
             ]
         });
-        return;
+        const data = {
+            meta: {
+                type: "ticketClosed",
+                displayName: "Ticket Archived",
+                calculateType: "ticketUpdate",
+                color: NucleusColors.yellow,
+                emoji: "GUILD.TICKET.ARCHIVED",
+                timestamp: new Date().getTime()
+            },
+            list: {
+                ticketFor: entry(
+                    uID!,
+                    renderUser((await interaction.guild.members.fetch(uID!)).user)
+                ),
+                archivedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user as Discord.User)),
+                archived: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+                ticketChannel: entry(channel.id, renderChannel(channel))
+            },
+            hidden: {
+                guild: interaction.guild.id
+            }
+        };
+        log(data);
     }
+    return;
 }
 
-async function purgeByUser(member, guild) {
+
+async function purgeByUser(member: string, guild: string) {
     const config = await client.database.guilds.read(guild.id);
+    const fetchedGuild = await client.guilds.fetch(guild);
     if (!config.tickets.category) return;
-    const tickets = guild.channels.cache.get(config.tickets.category);
+    const tickets = fetchedGuild.channels.cache.get(config.tickets.category);
     if (!tickets) return;
     const ticketChannels = tickets.children;
     let deleted = 0;
@@ -198,4 +185,4 @@
     }
 }
 
-export { purgeByUser };
+export { purgeByUser };
\ No newline at end of file