diff --git a/src/actions/roleMenu.ts b/src/actions/roleMenu.ts
index be58d99..8b15539 100644
--- a/src/actions/roleMenu.ts
+++ b/src/actions/roleMenu.ts
@@ -1,4 +1,4 @@
-import { unknownServerIcon } from './../utils/defaults.js';
+import { unknownServerIcon } from "./../utils/defaults.js";
 import {
     ButtonBuilder,
     CommandInteraction,
@@ -16,9 +16,9 @@
 import client from "../utils/client.js";
 import { LoadingEmbed } from "../utils/defaults.js";
 import type { GuildConfig } from "../utils/database.js";
-import { roleException } from '../utils/createTemporaryStorage.js';
-import addPlural from '../utils/plurals.js';
-import createPageIndicator from '../utils/createPageIndicator.js';
+import { roleException } from "../utils/createTemporaryStorage.js";
+import addPlural from "../utils/plurals.js";
+import createPageIndicator from "../utils/createPageIndicator.js";
 
 export interface RoleMenuSchema {
     guild: string;
@@ -42,23 +42,29 @@
     }[];
 }
 
-export const configToDropdown = (placeholder: string, currentPageData: ObjectSchema, selectedRoles?: string[]): ActionRowBuilder<StringSelectMenuBuilder> => {
+export const configToDropdown = (
+    placeholder: string,
+    currentPageData: ObjectSchema,
+    selectedRoles?: string[]
+): ActionRowBuilder<StringSelectMenuBuilder> => {
     return new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
         new StringSelectMenuBuilder()
             .setCustomId("roles")
             .setPlaceholder(placeholder)
             .setMinValues(currentPageData.min)
             .setMaxValues(currentPageData.max)
-            .addOptions(currentPageData.options.map((option: {name: string; description: string | null; role: string;}) => {
-                const builder = new StringSelectMenuOptionBuilder()
-                    .setLabel(option.name)
-                    .setValue(option.role)
-                    .setDefault(selectedRoles ? selectedRoles.includes(option.role) : false);
-                if (option.description) builder.setDescription(option.description);
-                return builder;
-            }))
-    )
-}
+            .addOptions(
+                currentPageData.options.map((option: { name: string; description: string | null; role: string }) => {
+                    const builder = new StringSelectMenuOptionBuilder()
+                        .setLabel(option.name)
+                        .setValue(option.role)
+                        .setDefault(selectedRoles ? selectedRoles.includes(option.role) : false);
+                    if (option.description) builder.setDescription(option.description);
+                    return builder;
+                })
+            )
+    );
+};
 
 export async function callback(interaction: CommandInteraction | ButtonInteraction) {
     if (!interaction.member) return;
@@ -69,7 +75,9 @@
             embeds: [
                 new EmojiEmbed()
                     .setTitle("Roles")
-                    .setDescription("Self roles are currently disabled. Please contact a staff member or try again later.")
+                    .setDescription(
+                        "Self roles are currently disabled. Please contact a staff member or try again later."
+                    )
                     .setStatus("Danger")
                     .setEmoji("GUILD.GREEN")
             ],
@@ -80,21 +88,24 @@
             embeds: [
                 new EmojiEmbed()
                     .setTitle("Roles")
-                    .setDescription("There are no roles available. Please contact a staff member if you believe this is a mistake.")
+                    .setDescription(
+                        "There are no roles available. Please contact a staff member if you believe this is a mistake."
+                    )
                     .setStatus("Danger")
                     .setEmoji("GUILD.GREEN")
             ],
             ephemeral: true
         });
     const m = await interaction.reply({ embeds: LoadingEmbed, ephemeral: true, fetchReply: true });
-    if (config.roleMenu.allowWebUI) {  // TODO: Make rolemenu web ui
-        const loginMethods: {webUI: boolean} = {
+    if (config.roleMenu.allowWebUI) {
+        // TODO: Make rolemenu web ui
+        const loginMethods: { webUI: boolean } = {
             webUI: false
-        }
+        };
         try {
             const status = await fetch(client.config.baseUrl).then((res) => res.status);
             if (status !== 200) loginMethods.webUI = false;
-        } catch(e) {
+        } catch (e) {
             loginMethods.webUI = false;
         }
         if (Object.values(loginMethods).some((i) => i)) {
@@ -105,7 +116,7 @@
                 const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
                 let valid = false;
                 while (!valid) {
-                    itt ++;
+                    itt++;
                     code = "";
                     for (let i = 0; i < length; i++) {
                         code += chars.charAt(Math.floor(Math.random() * chars.length));
@@ -113,7 +124,7 @@
                     if (code in client.roleMenu) continue;
                     if (itt > 1000) {
                         itt = 0;
-                        length ++;
+                        length++;
                         continue;
                     }
                     valid = true;
@@ -143,10 +154,7 @@
                             .setStyle(ButtonStyle.Link)
                             .setDisabled(!loginMethods.webUI)
                             .setURL(`${client.config.baseUrl}nucleus/rolemenu?code=${code}`),
-                        new ButtonBuilder()
-                            .setLabel("In Discord")
-                            .setStyle(ButtonStyle.Primary)
-                            .setCustomId("discord")
+                        new ButtonBuilder().setLabel("In Discord").setStyle(ButtonStyle.Primary).setCustomId("discord")
                     ])
                 ]
             });
@@ -154,7 +162,13 @@
             try {
                 component = await m.awaitMessageComponent({
                     time: 300000,
-                    filter: (i) => { return i.user.id === interaction.user.id && i.channelId === interaction.channelId  && i.message.id === m.id}
+                    filter: (i) => {
+                        return (
+                            i.user.id === interaction.user.id &&
+                            i.channelId === interaction.channelId &&
+                            i.message.id === m.id
+                        );
+                    }
                 });
             } catch (e) {
                 console.log(e);
@@ -168,22 +182,26 @@
     const selectedRoles: string[][] = [];
     const maxPage = options.length;
     const completedPages: boolean[] = options.map((option) => option.min === 0);
-    for (let i = 0; i < maxPage; i++) { selectedRoles.push([]); }
+    for (let i = 0; i < maxPage; i++) {
+        selectedRoles.push([]);
+    }
 
     let page = 0;
     let complete = completedPages.every((page) => page);
     let done = false;
 
     while (!(complete && done)) {
-        const currentPageData = options[page]!
+        const currentPageData = options[page]!;
         const embed = new EmojiEmbed()
             .setTitle("Roles")
             .setDescription(
                 `**${currentPageData.name}**\n` +
-                `> ${currentPageData.description}\n\n` +
-                (currentPageData.min === currentPageData.max ? `Select ${addPlural(currentPageData.min, "role")}` :
-                    `Select between ${currentPageData.min} and ${currentPageData.max} roles then press next`) + "\n\n" +
-                createPageIndicator(maxPage, page)
+                    `> ${currentPageData.description}\n\n` +
+                    (currentPageData.min === currentPageData.max
+                        ? `Select ${addPlural(currentPageData.min, "role")}`
+                        : `Select between ${currentPageData.min} and ${currentPageData.max} roles then press next`) +
+                    "\n\n" +
+                    createPageIndicator(maxPage, page)
             )
             .setStatus("Success")
             .setEmoji("GUILD.GREEN");
@@ -215,7 +233,13 @@
         try {
             component = await m.awaitMessageComponent({
                 time: 300000,
-                filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id && i.message.id === m.id}
+                filter: (i) => {
+                    return (
+                        i.user.id === interaction.user.id &&
+                        i.channel!.id === interaction.channel!.id &&
+                        i.message.id === m.id
+                    );
+                }
             });
         } catch (e) {
             console.log(e);
@@ -230,7 +254,7 @@
             done = true;
         } else if (component.customId === "roles" && component.isStringSelectMenu()) {
             selectedRoles[page] = component.values;
-            completedPages[page] = true
+            completedPages[page] = true;
             page = Math.min(maxPage - 1, page + 1);
         }
         complete = completedPages.every((page) => page);
@@ -238,14 +262,15 @@
 
     const fullRoleList: string[] = selectedRoles.flat();
 
-    const memberRoles = (interaction.member.roles as GuildMemberRoleManager).cache.map((r) => r.id);  // IDs
-    let rolesToRemove = config.roleMenu.options.map((o) => o.options.map((o) => o.role)).flat();  // IDs
-    rolesToRemove = rolesToRemove.filter((r) => memberRoles.includes(r)).filter((r) => !fullRoleList.includes(r))  // IDs
-    let roleObjectsToAdd = fullRoleList.map((r) => interaction.guild!.roles.cache.get(r))  // Role objects
+    const memberRoles = (interaction.member.roles as GuildMemberRoleManager).cache.map((r) => r.id); // IDs
+    let rolesToRemove = config.roleMenu.options.map((o) => o.options.map((o) => o.role)).flat(); // IDs
+    rolesToRemove = rolesToRemove.filter((r) => memberRoles.includes(r)).filter((r) => !fullRoleList.includes(r)); // IDs
+    let roleObjectsToAdd = fullRoleList
+        .map((r) => interaction.guild!.roles.cache.get(r)) // Role objects
         .filter((r) => r !== undefined) as Role[];
-    roleObjectsToAdd = roleObjectsToAdd.filter((r) => !memberRoles.includes(r.id));  // Role objects
+    roleObjectsToAdd = roleObjectsToAdd.filter((r) => !memberRoles.includes(r.id)); // Role objects
     try {
-        roleException(interaction.guild.id, interaction.user.id)
+        roleException(interaction.guild.id, interaction.user.id);
         await (interaction.member.roles as GuildMemberRoleManager).remove(rolesToRemove);
         await (interaction.member.roles as GuildMemberRoleManager).add(roleObjectsToAdd);
     } catch (e) {
