diff --git a/src/commands/nucleus/premium.ts b/src/commands/nucleus/premium.ts
index c431c8e..721bc5c 100644
--- a/src/commands/nucleus/premium.ts
+++ b/src/commands/nucleus/premium.ts
@@ -1,4 +1,14 @@
-import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction, ComponentType, Message, StringSelectMenuBuilder, StringSelectMenuInteraction } from "discord.js";
+import {
+    ActionRowBuilder,
+    ButtonBuilder,
+    ButtonInteraction,
+    ButtonStyle,
+    CommandInteraction,
+    ComponentType,
+    Message,
+    StringSelectMenuBuilder,
+    StringSelectMenuInteraction
+} from "discord.js";
 import type { SlashCommandSubcommandBuilder } from "discord.js";
 import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
 import client from "../../utils/client.js";
@@ -13,53 +23,54 @@
     let closed = false;
     do {
         const dbUser = await client.database.premium.fetchUser(interaction.user.id);
-        if(!dbUser) {
-            await interaction.editReply({embeds: [
-                new EmojiEmbed()
-                    .setTitle("Premium")
-                    .setDescription(`*You do not have premium! You can't activate premium on any servers.*` + firstDescription)
-                    .setEmoji("NUCLEUS.LOGO")
-                    .setStatus("Danger")
-            ]});
+        if (!dbUser) {
+            await interaction.editReply({
+                embeds: [
+                    new EmojiEmbed()
+                        .setTitle("Premium")
+                        .setDescription(
+                            `*You do not have premium! You can't activate premium on any servers.*` + firstDescription
+                        )
+                        .setEmoji("NUCLEUS.LOGO")
+                        .setStatus("Danger")
+                ]
+            });
             return;
         }
         const premiumGuilds = dbUser.appliesTo.map((guildID) => {
             const guild = client.guilds.cache.get(guildID);
-            if(!guild) return undefined;
+            if (!guild) return undefined;
             return guild.name;
         });
 
         const options = premiumGuilds.filter((guild) => guild !== undefined) as string[];
 
-        const removeRow = new ActionRowBuilder<StringSelectMenuBuilder>()
-            .addComponents(
-                new StringSelectMenuBuilder()
-                    .setCustomId("currentPremium")
-                    .setPlaceholder("Select a server to remove premium from")
-                    .setDisabled(premiumGuilds.length === 0)
-                    .addOptions(options.slice(0, Math.min(options.length, 24)).map((guild) => {
-                        return {label: guild, value: guild}
-                    }))
-            );
-        const cancel = new ActionRowBuilder<ButtonBuilder>()
-            .addComponents(
-                new ButtonBuilder()
-                    .setCustomId("cancel")
-                    .setLabel("Close")
-                    .setStyle(ButtonStyle.Danger)
-            );
+        const removeRow = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
+            new StringSelectMenuBuilder()
+                .setCustomId("currentPremium")
+                .setPlaceholder("Select a server to remove premium from")
+                .setDisabled(premiumGuilds.length === 0)
+                .addOptions(
+                    options.slice(0, Math.min(options.length, 24)).map((guild) => {
+                        return { label: guild, value: guild };
+                    })
+                )
+        );
+        const cancel = new ActionRowBuilder<ButtonBuilder>().addComponents(
+            new ButtonBuilder().setCustomId("cancel").setLabel("Close").setStyle(ButtonStyle.Danger)
+        );
 
         const components: ActionRowBuilder<StringSelectMenuBuilder | ButtonBuilder>[] = [cancel];
-        if(options.length > 0) components.unshift(removeRow);
-        await interaction.editReply(
-        {
+        if (options.length > 0) components.unshift(removeRow);
+        await interaction.editReply({
             embeds: [
                 new EmojiEmbed()
                     .setTitle("Premium")
                     .setDescription(
                         `*You have premium on the following servers:*\n\n` +
-                        (options.length > 0 ? options.join(', ') : `You have not activated premium in any guilds`) +
-                        firstDescription)
+                            (options.length > 0 ? options.join(", ") : `You have not activated premium in any guilds`) +
+                            firstDescription
+                    )
                     .setEmoji("NUCLEUS.LOGO")
                     .setStatus("Success")
             ],
@@ -69,43 +80,66 @@
         let i: StringSelectMenuInteraction | ButtonInteraction;
         try {
             const filter = (i: StringSelectMenuInteraction | ButtonInteraction) => i.user.id === interaction.user.id;
-            i = await msg.awaitMessageComponent<ComponentType.StringSelect | ComponentType.Button>({time: 300000, filter})
+            i = await msg.awaitMessageComponent<ComponentType.StringSelect | ComponentType.Button>({
+                time: 300000,
+                filter
+            });
         } catch (e) {
             await interaction.deleteReply();
             closed = true;
             break;
         }
         await i.deferUpdate();
-        if(i.isButton()) {
+        if (i.isButton()) {
             closed = true;
         } else {
             const response = client.database.premium.removePremium(interaction.user.id, i.values[0]!);
-            console.log(response)
+            console.log(response);
         }
     } while (!closed);
     await interaction.deleteReply();
-}
+};
 
 const callback = async (interaction: CommandInteraction): Promise<void> => {
     if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {});
-    const m = await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true})
-    const member = await (await interaction.client.guilds.fetch("684492926528651336")).members.fetch(interaction.user.id).catch(() => {
-        interaction.editReply({ embeds: [
-            new EmojiEmbed()
-                .setTitle("Premium")
-                .setDescription(`*You are not currently in the Clicks Server. To gain access to premium please join.*` + firstDescription)
-                .setEmoji("NUCLEUS.LOGO")
-                .setStatus("Danger")
-        ], components: [new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setStyle(ButtonStyle.Link).setLabel("Join").setURL("https://discord.gg/bPaNnxe"))] });
-    })
+    const m = await interaction.reply({ embeds: LoadingEmbed, ephemeral: true, fetchReply: true });
+    const member = await (await interaction.client.guilds.fetch("684492926528651336")).members
+        .fetch(interaction.user.id)
+        .catch(() => {
+            interaction.editReply({
+                embeds: [
+                    new EmojiEmbed()
+                        .setTitle("Premium")
+                        .setDescription(
+                            `*You are not currently in the Clicks Server. To gain access to premium please join.*` +
+                                firstDescription
+                        )
+                        .setEmoji("NUCLEUS.LOGO")
+                        .setStatus("Danger")
+                ],
+                components: [
+                    new ActionRowBuilder<ButtonBuilder>().addComponents(
+                        new ButtonBuilder()
+                            .setStyle(ButtonStyle.Link)
+                            .setLabel("Join")
+                            .setURL("https://discord.gg/bPaNnxe")
+                    )
+                ]
+            });
+        });
     if (!member) return;
-    const firstDescription = "\n\nPremium allows servers of your choice to get access to extra features for a fixed price per month.\nThis includes:\n" +
-        `${getEmojiByName("MOD.IMAGES.TOOSMALL")}  Attachment logs - Stores attachments so they can be viewed after a message is deleted.\n` +
-        `${getEmojiByName("GUILD.TICKET.ARCHIVED")}  Ticket Transcripts - Gives a link to view the history of a ticket after it has been closed.\n`
-    const dbMember = await client.database.premium.fetchUser(interaction.user.id)
+    const firstDescription =
+        "\n\nPremium allows servers of your choice to get access to extra features for a fixed price per month.\nThis includes:\n" +
+        `${getEmojiByName(
+            "MOD.IMAGES.TOOSMALL"
+        )}  Attachment logs - Stores attachments so they can be viewed after a message is deleted.\n` +
+        `${getEmojiByName(
+            "GUILD.TICKET.ARCHIVED"
+        )}  Ticket Transcripts - Gives a link to view the history of a ticket after it has been closed.\n`;
+    const dbMember = await client.database.premium.fetchUser(interaction.user.id);
     let premium = `You do not have premium! You can't activate premium on any servers.`;
     let count = 0;
-    const {level, appliesTo} = dbMember ?? {level: 0, appliesTo: []}
+    const { level, appliesTo } = dbMember ?? { level: 0, appliesTo: [] };
     if (level === 99) {
         premium = `You have Infinite Premium! You have been gifted this by the developers as a thank you. You can give premium to any and all servers you are in.`;
         count = 200;
@@ -116,51 +150,53 @@
         premium = `You have Premium tier 2! You can give premium to ${3 - appliesTo.length} more server(s).`;
         count = 3;
     } else if (level === 3) {
-        premium = `You have Premium Mod! You can give premium to ${3 - appliesTo.length} more server(s), as well as automatically giving premium to all servers you have a "manage" permission in.`
+        premium = `You have Premium Mod! You can give premium to ${
+            3 - appliesTo.length
+        } more server(s), as well as automatically giving premium to all servers you have a "manage" permission in.`;
         count = 3;
     }
     if (dbMember?.expiresAt) {
-        premium = `**You can't give servers premium anymore because your subscription ended or was cancelled.** To get premium again please subscribe in the Clicks server`
+        premium = `**You can't give servers premium anymore because your subscription ended or was cancelled.** To get premium again please subscribe in the Clicks server`;
         count = 0;
     }
-    if(!interaction.guild) return await dmcallback(interaction, firstDescription, m);
+    if (!interaction.guild) return await dmcallback(interaction, firstDescription, m);
     const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
-    let premiumGuild = ""
+    let premiumGuild = "";
     if (hasPremium) {
-        premiumGuild = `**This server has premium! It was ${hasPremium[2] === 3 && hasPremium[3] ? `automatically applied by <@${hasPremium[1]}>` : `given by <@${hasPremium[1]}>`}**\n\n`
+        premiumGuild = `**This server has premium! It was ${
+            hasPremium[2] === 3 && hasPremium[3]
+                ? `automatically applied by <@${hasPremium[1]}>`
+                : `given by <@${hasPremium[1]}>`
+        }**\n\n`;
     }
 
-    const components: ActionRowBuilder<ButtonBuilder>[] = []
+    const components: ActionRowBuilder<ButtonBuilder>[] = [];
     if (level === 0 || dbMember?.expiresAt) {
         components.push(
-            new ActionRowBuilder<ButtonBuilder>()
-                .addComponents(
-                    new ButtonBuilder()
+            new ActionRowBuilder<ButtonBuilder>().addComponents(
+                new ButtonBuilder()
                     .setStyle(ButtonStyle.Link)
                     .setLabel("Join Clicks")
                     .setURL("https://discord.gg/bPaNnxe")
-                )
-        )
+            )
+        );
     } else {
         components.push(
-            new ActionRowBuilder<ButtonBuilder>()
-                .addComponents(
-                    new ButtonBuilder()
-                        .setStyle(premiumGuild.length > 0 ? ButtonStyle.Secondary : ButtonStyle.Success)
-                        .setLabel(premiumGuild.length > 0 ? "This server has premium" : "Activate premium here")
-                        .setCustomId("premiumActivate")
-                        .setDisabled(count <= 0 || (hasPremium ? hasPremium[0] : false))
-                )
-        )
+            new ActionRowBuilder<ButtonBuilder>().addComponents(
+                new ButtonBuilder()
+                    .setStyle(premiumGuild.length > 0 ? ButtonStyle.Secondary : ButtonStyle.Success)
+                    .setLabel(premiumGuild.length > 0 ? "This server has premium" : "Activate premium here")
+                    .setCustomId("premiumActivate")
+                    .setDisabled(count <= 0 || (hasPremium ? hasPremium[0] : false))
+            )
+        );
     }
 
     interaction.editReply({
         embeds: [
             new EmojiEmbed()
                 .setTitle("Premium")
-                .setDescription(
-                    premiumGuild + premium + firstDescription
-                )
+                .setDescription(premiumGuild + premium + firstDescription)
                 .setEmoji("NUCLEUS.LOGO")
                 .setStatus("Danger")
                 .setImage("https://assets.clicks.codes/ads/ads/nucleus-premium.png")
@@ -196,9 +232,7 @@
             embeds: [
                 new EmojiEmbed()
                     .setTitle("Premium")
-                    .setDescription(
-                        `You have activated premium on this server!` + firstDescription
-                    )
+                    .setDescription(`You have activated premium on this server!` + firstDescription)
                     .setEmoji("NUCLEUS.LOGO")
                     .setStatus("Danger")
             ],
