diff --git a/src/premium/attachmentLogs.ts b/src/premium/attachmentLogs.ts
index 5a771bc..679627d 100644
--- a/src/premium/attachmentLogs.ts
+++ b/src/premium/attachmentLogs.ts
@@ -6,60 +6,98 @@
 import addPlural from "../utils/plurals.js";
 import type { Message } from "discord.js";
 
-
-export default async function logAttachment(message: Message): Promise<AttachmentLogSchema> {
-    if (!message.guild) throw new Error("Tried to log an attachment in a non-guild message");
+export default async function logAttachment(
+    message: Message
+): Promise<AttachmentLogSchema> {
+    if (!message.guild)
+        throw new Error("Tried to log an attachment in a non-guild message");
     const { renderUser, renderChannel, renderDelta } = client.logger;
     const attachments = [];
     for (const attachment of message.attachments.values()) {
-        attachments.push({local: await saveAttachment(attachment.url), url: attachment.url, height: attachment.height, width: attachment.width, size: attachment.size});
+        attachments.push({
+            local: await saveAttachment(attachment.url),
+            url: attachment.url,
+            height: attachment.height,
+            width: attachment.width,
+            size: attachment.size
+        });
     }
     const links = message.content.match(/https?:\/\/\S+/gi) || [];
     for (const link of links) {
-        if (link.toLowerCase().match(/\.(jpg|jpeg|png|gif|gifv|webm|webp|mp4|wav|mp3|ogg)$/gi)) {
-            attachments.push({local: await saveAttachment(link), url: link, height: null, width: null});
+        if (
+            link
+                .toLowerCase()
+                .match(/\.(jpg|jpeg|png|gif|gifv|webm|webp|mp4|wav|mp3|ogg)$/gi)
+        ) {
+            attachments.push({
+                local: await saveAttachment(link),
+                url: link,
+                height: null,
+                width: null
+            });
         }
     }
-    if (attachments.length === 0) return {files: []};
+    if (attachments.length === 0) return { files: [] };
     if (client.database.premium.hasPremium(message.guild.id)) {
-        const channel = (await client.database.guilds.read(message.guild.id)).logging.attachments.channel;
+        const channel = (await client.database.guilds.read(message.guild.id))
+            .logging.attachments.channel;
         if (!channel) {
-            singleNotify("noAttachmentLogChannel", message.guild.id, "No channel set for attachment logging", "Warning");
-            return {files: attachments};
+            singleNotify(
+                "noAttachmentLogChannel",
+                message.guild.id,
+                "No channel set for attachment logging",
+                "Warning"
+            );
+            return { files: attachments };
         }
         const channelObj = await client.channels.fetch(channel);
         if (!channelObj) {
-            singleNotify("attachmentLogChannelDeleted", message.guild.id, "Attachment history channel was deleted", "Warning");
-            return {files: attachments};
+            singleNotify(
+                "attachmentLogChannelDeleted",
+                message.guild.id,
+                "Attachment history channel was deleted",
+                "Warning"
+            );
+            return { files: attachments };
         }
-        const m = await channelObj.send({embeds: [new EmojiEmbed()
-            .setTitle(`${addPlural(attachments.length, "Attachment")} Sent`)
-            .setDescription(keyValueList({
-                "messageId": `\`${message.id}\``,
-                "sentBy": renderUser(message.author),
-                "sentIn": renderChannel(message.channel),
-                "sent": renderDelta(new Date(message.createdTimestamp))
-            }) + `\n[[Jump to message]](${message.url})`)
-            .setEmoji("ICONS.ATTACHMENT")
-            .setStatus("Success")
-        ], files: attachments.map(file => file.local)});
+        const m = await channelObj.send({
+            embeds: [
+                new EmojiEmbed()
+                    .setTitle(
+                        `${addPlural(attachments.length, "Attachment")} Sent`
+                    )
+                    .setDescription(
+                        keyValueList({
+                            messageId: `\`${message.id}\``,
+                            sentBy: renderUser(message.author),
+                            sentIn: renderChannel(message.channel),
+                            sent: renderDelta(
+                                new Date(message.createdTimestamp)
+                            )
+                        }) + `\n[[Jump to message]](${message.url})`
+                    )
+                    .setEmoji("ICONS.ATTACHMENT")
+                    .setStatus("Success")
+            ],
+            files: attachments.map((file) => file.local)
+        });
         // await client.database.guilds.write(interaction.guild.id, {[`tags.${name}`]: value});
-        client.database.guilds.write(
-            message.guild.id,
-            {[`logging.attachments.saved.${message.channel.id}${message.id}`]: m.url}
-        );
-        return {files: attachments, jump: m.url};
+        client.database.guilds.write(message.guild.id, {
+            [`logging.attachments.saved.${message.channel.id}${message.id}`]:
+                m.url
+        });
+        return { files: attachments, jump: m.url };
     } else {
-        return {files: attachments};
+        return { files: attachments };
     }
 }
 
 export interface AttachmentLogSchema {
     files: {
-        url: string,
-        local: string,
-        height: number | null,
-        width: number | null
-    }[],
+        url: string;
+        local: string;
+        height: number | null;
+        width: number | null;
+    }[];
     jump?: string;
-}
\ No newline at end of file
+}
diff --git a/src/premium/createTranscript.ts b/src/premium/createTranscript.ts
index d5d7bb8..3d7f4c6 100644
--- a/src/premium/createTranscript.ts
+++ b/src/premium/createTranscript.ts
@@ -2,86 +2,125 @@
 import EmojiEmbed from "../utils/generateEmojiEmbed.js";
 import getEmojiByName from "../utils/getEmojiByName.js";
 import { PasteClient, Publicity, ExpireDate } from "pastebin-api";
-import config from "../config/main.json" assert {type: "json"};
+import config from "../config/main.json" assert { type: "json" };
 import client from "../utils/client.js";
 
 const pbClient = new PasteClient(config.pastebinApiKey);
 
 export default async function (interaction) {
-    const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
+    const { log, NucleusColors, entry, renderUser, renderDelta } =
+        client.logger;
 
     let messages = [];
     let deleted = 100;
 
     while (deleted === 100) {
         let fetched;
-        await (interaction.channel as TextChannel).messages.fetch({limit: 100}).then(async (ms) => {
-            fetched = await (interaction.channel as TextChannel).bulkDelete(ms, true);
-        });
+        await (interaction.channel as TextChannel).messages
+            .fetch({ limit: 100 })
+            .then(async (ms) => {
+                fetched = await (interaction.channel as TextChannel).bulkDelete(
+                    ms,
+                    true
+                );
+            });
         deleted = fetched.size;
         if (fetched) {
-            messages = messages.concat(fetched.map(m => m));
+            messages = messages.concat(fetched.map((m) => m));
         }
     }
     let out = "";
-    messages.reverse().forEach(message => {
+    messages.reverse().forEach((message) => {
         if (!message.author.bot) {
             const sentDate = new Date(message.createdTimestamp);
-            out += `${message.author.username}#${message.author.discriminator} (${message.author.id}) [${sentDate.toUTCString()}]\n`;
+            out += `${message.author.username}#${
+                message.author.discriminator
+            } (${message.author.id}) [${sentDate.toUTCString()}]\n`;
             const lines = message.content.split("\n");
-            lines.forEach(line => {out += `> ${line}\n`;});
+            lines.forEach((line) => {
+                out += `> ${line}\n`;
+            });
             out += "\n\n";
         }
     });
-    const member = interaction.channel.guild.members.cache.get(interaction.channel.topic.split(" ")[0]);
+    const member = interaction.channel.guild.members.cache.get(
+        interaction.channel.topic.split(" ")[0]
+    );
     let m;
     if (out !== "") {
         const url = await pbClient.createPaste({
             code: out,
             expireDate: ExpireDate.Never,
-            name: `Ticket Transcript for ${member.user.username}#${member.user.discriminator} (Created at ${new Date(interaction.channel.createdTimestamp).toDateString()})`,
+            name: `Ticket Transcript for ${member.user.username}#${
+                member.user.discriminator
+            } (Created at ${new Date(
+                interaction.channel.createdTimestamp
+            ).toDateString()})`,
             publicity: Publicity.Unlisted
         });
-        const guildConfig = await client.database.guilds.read(interaction.guild.id);
-        m = await interaction.reply({embeds: [new EmojiEmbed()
-            .setTitle("Transcript")
-            .setDescription("You can view the transcript using the link below. You can save the link for later" + (guildConfig.logging.logs.channel ?
-                ` or find it in <#${guildConfig.logging.logs.channel}> once you press delete below. After this the channel will be deleted.`
-                : "."))
-            .setStatus("Success")
-            .setEmoji("CONTROL.DOWNLOAD")
-        ], components: [new MessageActionRow().addComponents([
-            new MessageButton()
-                .setLabel("View")
-                .setStyle("LINK")
-                .setURL(url),
-            new MessageButton()
-                .setLabel("Delete")
-                .setStyle("DANGER")
-                .setCustomId("close")
-                .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
-        ])], fetchReply: true});
+        const guildConfig = await client.database.guilds.read(
+            interaction.guild.id
+        );
+        m = await interaction.reply({
+            embeds: [
+                new EmojiEmbed()
+                    .setTitle("Transcript")
+                    .setDescription(
+                        "You can view the transcript using the link below. You can save the link for later" +
+                            (guildConfig.logging.logs.channel
+                                ? ` or find it in <#${guildConfig.logging.logs.channel}> once you press delete below. After this the channel will be deleted.`
+                                : ".")
+                    )
+                    .setStatus("Success")
+                    .setEmoji("CONTROL.DOWNLOAD")
+            ],
+            components: [
+                new MessageActionRow().addComponents([
+                    new MessageButton()
+                        .setLabel("View")
+                        .setStyle("LINK")
+                        .setURL(url),
+                    new MessageButton()
+                        .setLabel("Delete")
+                        .setStyle("DANGER")
+                        .setCustomId("close")
+                        .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+                ])
+            ],
+            fetchReply: true
+        });
     } else {
-        m = await interaction.reply({embeds: [new EmojiEmbed()
-            .setTitle("Transcript")
-            .setDescription("The transcript was empty, so no changes were made. To delete this ticket, press the delete button below.")
-            .setStatus("Success")
-            .setEmoji("CONTROL.DOWNLOAD")
-        ], components: [new MessageActionRow().addComponents([
-            new MessageButton()
-                .setLabel("Delete")
-                .setStyle("DANGER")
-                .setCustomId("close")
-                .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
-        ])], fetchReply: true});
+        m = await interaction.reply({
+            embeds: [
+                new EmojiEmbed()
+                    .setTitle("Transcript")
+                    .setDescription(
+                        "The transcript was empty, so no changes were made. To delete this ticket, press the delete button below."
+                    )
+                    .setStatus("Success")
+                    .setEmoji("CONTROL.DOWNLOAD")
+            ],
+            components: [
+                new MessageActionRow().addComponents([
+                    new MessageButton()
+                        .setLabel("Delete")
+                        .setStyle("DANGER")
+                        .setCustomId("close")
+                        .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+                ])
+            ],
+            fetchReply: true
+        });
     }
     let i;
     try {
         i = await m.awaitMessageComponent({ time: 300000 });
         i.deferUpdate();
-    } catch { return; }
+    } catch {
+        return;
+    }
     const data = {
-        meta:{
+        meta: {
             type: "ticketDeleted",
             displayName: "Ticket Deleted",
             calculateType: "ticketUpdate",
@@ -90,9 +129,24 @@
             timestamp: new Date().getTime()
         },
         list: {
-            ticketFor: entry(interaction.channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(interaction.channel.topic.split(" ")[0])).user)),
-            deletedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
-            deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
+            ticketFor: entry(
+                interaction.channel.topic.split(" ")[0],
+                renderUser(
+                    (
+                        await interaction.guild.members.fetch(
+                            interaction.channel.topic.split(" ")[0]
+                        )
+                    ).user
+                )
+            ),
+            deletedBy: entry(
+                interaction.member.user.id,
+                renderUser(interaction.member.user)
+            ),
+            deleted: entry(
+                new Date().getTime(),
+                renderDelta(new Date().getTime())
+            )
         },
         hidden: {
             guild: interaction.guild.id
@@ -101,4 +155,4 @@
     log(data);
     await interaction.channel.delete();
     return;
-}
\ No newline at end of file
+}
