diff --git a/src/commands/mod/mute.ts b/src/commands/mod/mute.ts
index 1e9a812..5be6f43 100644
--- a/src/commands/mod/mute.ts
+++ b/src/commands/mod/mute.ts
@@ -1,5 +1,11 @@
 import { LoadingEmbed } from "./../../utils/defaultEmbeds.js";
-import Discord, { CommandInteraction, GuildMember, Message, MessageActionRow, MessageButton } from "discord.js";
+import Discord, {
+    CommandInteraction,
+    GuildMember,
+    Message,
+    MessageActionRow,
+    MessageButton
+} from "discord.js";
 import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
 import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
 import getEmojiByName from "../../utils/getEmojiByName.js";
@@ -7,20 +13,69 @@
 import keyValueList from "../../utils/generateKeyValueList.js";
 import humanizeDuration from "humanize-duration";
 import client from "../../utils/client.js";
-import { areTicketsEnabled, create } from "../../actions/createModActionTicket.js";
+import {
+    areTicketsEnabled,
+    create
+} from "../../actions/createModActionTicket.js";
 
 const command = (builder: SlashCommandSubcommandBuilder) =>
     builder
         .setName("mute")
-        .setDescription("Mutes a member, stopping them from talking in the server")
-        .addUserOption(option => option.setName("user").setDescription("The user to mute").setRequired(true))
-        .addIntegerOption(option => option.setName("days").setDescription("The number of days to mute the user for | Default: 0").setMinValue(0).setMaxValue(27).setRequired(false))
-        .addIntegerOption(option => option.setName("hours").setDescription("The number of hours to mute the user for | Default: 0").setMinValue(0).setMaxValue(23).setRequired(false))
-        .addIntegerOption(option => option.setName("minutes").setDescription("The number of minutes to mute the user for | Default: 0").setMinValue(0).setMaxValue(59).setRequired(false))
-        .addIntegerOption(option => option.setName("seconds").setDescription("The number of seconds to mute the user for | Default: 0").setMinValue(0).setMaxValue(59).setRequired(false));
+        .setDescription(
+            "Mutes a member, stopping them from talking in the server"
+        )
+        .addUserOption((option) =>
+            option
+                .setName("user")
+                .setDescription("The user to mute")
+                .setRequired(true)
+        )
+        .addIntegerOption((option) =>
+            option
+                .setName("days")
+                .setDescription(
+                    "The number of days to mute the user for | Default: 0"
+                )
+                .setMinValue(0)
+                .setMaxValue(27)
+                .setRequired(false)
+        )
+        .addIntegerOption((option) =>
+            option
+                .setName("hours")
+                .setDescription(
+                    "The number of hours to mute the user for | Default: 0"
+                )
+                .setMinValue(0)
+                .setMaxValue(23)
+                .setRequired(false)
+        )
+        .addIntegerOption((option) =>
+            option
+                .setName("minutes")
+                .setDescription(
+                    "The number of minutes to mute the user for | Default: 0"
+                )
+                .setMinValue(0)
+                .setMaxValue(59)
+                .setRequired(false)
+        )
+        .addIntegerOption((option) =>
+            option
+                .setName("seconds")
+                .setDescription(
+                    "The number of seconds to mute the user for | Default: 0"
+                )
+                .setMinValue(0)
+                .setMaxValue(59)
+                .setRequired(false)
+        );
 
-const callback = async (interaction: CommandInteraction): Promise<void | unknown> => {
-    const { log, NucleusColors, renderUser, entry, renderDelta } = client.logger;
+const callback = async (
+    interaction: CommandInteraction
+): Promise<void | unknown> => {
+    const { log, NucleusColors, renderUser, entry, renderDelta } =
+        client.logger;
     const user = interaction.options.getMember("user") as GuildMember;
     const time = {
         days: interaction.options.getInteger("days") || 0,
@@ -29,85 +84,136 @@
         seconds: interaction.options.getInteger("seconds") || 0
     };
     const config = await client.database.guilds.read(interaction.guild.id);
-    let serverSettingsDescription = (config.moderation.mute.timeout ? "given a timeout" : "");
-    if (config.moderation.mute.role) serverSettingsDescription += (serverSettingsDescription ? " and " : "") + `given the <@&${config.moderation.mute.role}> role`;
+    let serverSettingsDescription = config.moderation.mute.timeout
+        ? "given a timeout"
+        : "";
+    if (config.moderation.mute.role)
+        serverSettingsDescription +=
+            (serverSettingsDescription ? " and " : "") +
+            `given the <@&${config.moderation.mute.role}> role`;
 
-    let muteTime = (time.days * 24 * 60 * 60) + (time.hours * 60 * 60) + (time.minutes * 60) + time.seconds;
+    let muteTime =
+        time.days * 24 * 60 * 60 +
+        time.hours * 60 * 60 +
+        time.minutes * 60 +
+        time.seconds;
     if (muteTime === 0) {
-        const m = await interaction.reply({embeds: [
-            new EmojiEmbed()
-                .setEmoji("PUNISH.MUTE.GREEN")
-                .setTitle("Mute")
-                .setDescription("How long should the user be muted")
-                .setStatus("Success")
-        ], components: [
-            new MessageActionRow().addComponents([
-                new Discord.MessageButton()
-                    .setCustomId("1m")
-                    .setLabel("1 Minute")
-                    .setStyle("SECONDARY"),
-                new Discord.MessageButton()
-                    .setCustomId("10m")
-                    .setLabel("10 Minutes")
-                    .setStyle("SECONDARY"),
-                new Discord.MessageButton()
-                    .setCustomId("30m")
-                    .setLabel("30 Minutes")
-                    .setStyle("SECONDARY"),
-                new Discord.MessageButton()
-                    .setCustomId("1h")
-                    .setLabel("1 Hour")
-                    .setStyle("SECONDARY")
-            ]),
-            new MessageActionRow().addComponents([
-                new Discord.MessageButton()
-                    .setCustomId("6h")
-                    .setLabel("6 Hours")
-                    .setStyle("SECONDARY"),
-                new Discord.MessageButton()
-                    .setCustomId("12h")
-                    .setLabel("12 Hours")
-                    .setStyle("SECONDARY"),
-                new Discord.MessageButton()
-                    .setCustomId("1d")
-                    .setLabel("1 Day")
-                    .setStyle("SECONDARY"),
-                new Discord.MessageButton()
-                    .setCustomId("1w")
-                    .setLabel("1 Week")
-                    .setStyle("SECONDARY")
-            ]),
-            new MessageActionRow().addComponents([
-                new Discord.MessageButton()
-                    .setCustomId("cancel")
-                    .setLabel("Cancel")
-                    .setStyle("DANGER")
-                    .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
-            ])
-        ], ephemeral: true, fetchReply: true}) as Message;
+        const m = (await interaction.reply({
+            embeds: [
+                new EmojiEmbed()
+                    .setEmoji("PUNISH.MUTE.GREEN")
+                    .setTitle("Mute")
+                    .setDescription("How long should the user be muted")
+                    .setStatus("Success")
+            ],
+            components: [
+                new MessageActionRow().addComponents([
+                    new Discord.MessageButton()
+                        .setCustomId("1m")
+                        .setLabel("1 Minute")
+                        .setStyle("SECONDARY"),
+                    new Discord.MessageButton()
+                        .setCustomId("10m")
+                        .setLabel("10 Minutes")
+                        .setStyle("SECONDARY"),
+                    new Discord.MessageButton()
+                        .setCustomId("30m")
+                        .setLabel("30 Minutes")
+                        .setStyle("SECONDARY"),
+                    new Discord.MessageButton()
+                        .setCustomId("1h")
+                        .setLabel("1 Hour")
+                        .setStyle("SECONDARY")
+                ]),
+                new MessageActionRow().addComponents([
+                    new Discord.MessageButton()
+                        .setCustomId("6h")
+                        .setLabel("6 Hours")
+                        .setStyle("SECONDARY"),
+                    new Discord.MessageButton()
+                        .setCustomId("12h")
+                        .setLabel("12 Hours")
+                        .setStyle("SECONDARY"),
+                    new Discord.MessageButton()
+                        .setCustomId("1d")
+                        .setLabel("1 Day")
+                        .setStyle("SECONDARY"),
+                    new Discord.MessageButton()
+                        .setCustomId("1w")
+                        .setLabel("1 Week")
+                        .setStyle("SECONDARY")
+                ]),
+                new MessageActionRow().addComponents([
+                    new Discord.MessageButton()
+                        .setCustomId("cancel")
+                        .setLabel("Cancel")
+                        .setStyle("DANGER")
+                        .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+                ])
+            ],
+            ephemeral: true,
+            fetchReply: true
+        })) as Message;
         let component;
         try {
-            component = await m.awaitMessageComponent({filter: (m) => m.user.id === interaction.user.id, time: 300000});
-        } catch { return; }
+            component = await m.awaitMessageComponent({
+                filter: (m) => m.user.id === interaction.user.id,
+                time: 300000
+            });
+        } catch {
+            return;
+        }
         component.deferUpdate();
-        if (component.customId === "cancel") return interaction.editReply({embeds: [new EmojiEmbed()
-            .setEmoji("PUNISH.MUTE.RED")
-            .setTitle("Mute")
-            .setDescription("Mute cancelled")
-            .setStatus("Danger")
-        ]});
+        if (component.customId === "cancel")
+            return interaction.editReply({
+                embeds: [
+                    new EmojiEmbed()
+                        .setEmoji("PUNISH.MUTE.RED")
+                        .setTitle("Mute")
+                        .setDescription("Mute cancelled")
+                        .setStatus("Danger")
+                ]
+            });
         switch (component.customId) {
-        case "1m": { muteTime = 60; break; }
-        case "10m": { muteTime = 60 * 10; break; }
-        case "30m": { muteTime = 60 * 30; break; }
-        case "1h": { muteTime = 60 * 60; break; }
-        case "6h": { muteTime = 60 * 60 * 6; break; }
-        case "12h": { muteTime = 60 * 60 * 12; break; }
-        case "1d": { muteTime = 60 * 60 * 24; break; }
-        case "1w": { muteTime = 60 * 60 * 24 * 7; break; }
+            case "1m": {
+                muteTime = 60;
+                break;
+            }
+            case "10m": {
+                muteTime = 60 * 10;
+                break;
+            }
+            case "30m": {
+                muteTime = 60 * 30;
+                break;
+            }
+            case "1h": {
+                muteTime = 60 * 60;
+                break;
+            }
+            case "6h": {
+                muteTime = 60 * 60 * 6;
+                break;
+            }
+            case "12h": {
+                muteTime = 60 * 60 * 12;
+                break;
+            }
+            case "1d": {
+                muteTime = 60 * 60 * 24;
+                break;
+            }
+            case "1w": {
+                muteTime = 60 * 60 * 24 * 7;
+                break;
+            }
         }
     } else {
-        await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true});
+        await interaction.reply({
+            embeds: LoadingEmbed,
+            ephemeral: true,
+            fetchReply: true
+        });
     }
     // TODO:[Modals] Replace this with a modal
     let reason = null;
@@ -118,20 +224,47 @@
         confirmation = await new confirmationMessage(interaction)
             .setEmoji("PUNISH.MUTE.RED")
             .setTitle("Mute")
-            .setDescription(keyValueList({
-                "user": renderUser(user.user),
-                "time": `${humanizeDuration(muteTime * 1000, {round: true})}`,
-                "reason": reason ?  ("\n> " + ((reason ?? "").replaceAll("\n", "\n> "))) : "*No reason provided*"
-            })
-            + "The user will be " + serverSettingsDescription + "\n"
-            + `The user **will${notify ? "" : " not"}** be notified\n\n`
-            + `Are you sure you want to mute <@!${user.id}>?`)
+            .setDescription(
+                keyValueList({
+                    user: renderUser(user.user),
+                    time: `${humanizeDuration(muteTime * 1000, {
+                        round: true
+                    })}`,
+                    reason: reason
+                        ? "\n> " + (reason ?? "").replaceAll("\n", "\n> ")
+                        : "*No reason provided*"
+                }) +
+                    "The user will be " +
+                    serverSettingsDescription +
+                    "\n" +
+                    `The user **will${notify ? "" : " not"}** be notified\n\n` +
+                    `Are you sure you want to mute <@!${user.id}>?`
+            )
             .setColor("Danger")
             .addCustomBoolean(
-                "appeal", "Create appeal ticket", !(await areTicketsEnabled(interaction.guild.id)),
-                async () => await create(interaction.guild, interaction.options.getUser("user"), interaction.user, reason),
-                "An appeal ticket will be created when Confirm is clicked", "CONTROL.TICKET", createAppealTicket)
-            .addCustomBoolean("notify", "Notify user", false, null, null, "ICONS.NOTIFY." + (notify ? "ON" : "OFF" ), notify)
+                "appeal",
+                "Create appeal ticket",
+                !(await areTicketsEnabled(interaction.guild.id)),
+                async () =>
+                    await create(
+                        interaction.guild,
+                        interaction.options.getUser("user"),
+                        interaction.user,
+                        reason
+                    ),
+                "An appeal ticket will be created when Confirm is clicked",
+                "CONTROL.TICKET",
+                createAppealTicket
+            )
+            .addCustomBoolean(
+                "notify",
+                "Notify user",
+                false,
+                null,
+                null,
+                "ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
+                notify
+            )
             .addReasonButton(reason ?? "")
             .send(true);
         reason = reason ?? "";
@@ -150,69 +283,135 @@
         try {
             if (notify) {
                 dm = await user.send({
-                    embeds: [new EmojiEmbed()
-                        .setEmoji("PUNISH.MUTE.RED")
-                        .setTitle("Muted")
-                        .setDescription(`You have been muted in ${interaction.guild.name}` +
-                                    (reason ? ` for:\n> ${reason}` : ".\n\n" +
-                                    `You will be unmuted at: <t:${Math.round((new Date).getTime() / 1000) + muteTime}:D> at <t:${Math.round((new Date).getTime() / 1000) + muteTime}:T> (<t:${Math.round((new Date).getTime() / 1000) + muteTime}:R>)`) +
-                                    (confirmation.components.appeal.response ? `You can appeal this here: <#${confirmation.components.appeal.response}>` : ""))
-                        .setStatus("Danger")
+                    embeds: [
+                        new EmojiEmbed()
+                            .setEmoji("PUNISH.MUTE.RED")
+                            .setTitle("Muted")
+                            .setDescription(
+                                `You have been muted in ${interaction.guild.name}` +
+                                    (reason
+                                        ? ` for:\n> ${reason}`
+                                        : ".\n\n" +
+                                          `You will be unmuted at: <t:${
+                                              Math.round(
+                                                  new Date().getTime() / 1000
+                                              ) + muteTime
+                                          }:D> at <t:${
+                                              Math.round(
+                                                  new Date().getTime() / 1000
+                                              ) + muteTime
+                                          }:T> (<t:${
+                                              Math.round(
+                                                  new Date().getTime() / 1000
+                                              ) + muteTime
+                                          }:R>)`) +
+                                    (confirmation.components.appeal.response
+                                        ? `You can appeal this here: <#${confirmation.components.appeal.response}>`
+                                        : "")
+                            )
+                            .setStatus("Danger")
                     ],
-                    components: [new MessageActionRow().addComponents(config.moderation.mute.text ? [new MessageButton()
-                        .setStyle("LINK")
-                        .setLabel(config.moderation.mute.text)
-                        .setURL(config.moderation.mute.link)
-                    ] : [])]
+                    components: [
+                        new MessageActionRow().addComponents(
+                            config.moderation.mute.text
+                                ? [
+                                      new MessageButton()
+                                          .setStyle("LINK")
+                                          .setLabel(config.moderation.mute.text)
+                                          .setURL(config.moderation.mute.link)
+                                  ]
+                                : []
+                        )
+                    ]
                 });
                 dmd = true;
             }
-        } catch { dmd = false; }
+        } catch {
+            dmd = false;
+        }
         const member = user;
         let errors = 0;
         try {
             if (config.moderation.mute.timeout) {
-                await member.timeout(muteTime * 1000, reason || "No reason provided");
+                await member.timeout(
+                    muteTime * 1000,
+                    reason || "No reason provided"
+                );
                 if (config.moderation.mute.role !== null) {
                     await member.roles.add(config.moderation.mute.role);
-                    await client.database.eventScheduler.schedule("naturalUnmute", new Date().getTime() + muteTime * 1000, {
-                        guild: interaction.guild.id,
-                        user: user.id,
-                        expires: new Date().getTime() + muteTime * 1000
-                    });
+                    await client.database.eventScheduler.schedule(
+                        "naturalUnmute",
+                        new Date().getTime() + muteTime * 1000,
+                        {
+                            guild: interaction.guild.id,
+                            user: user.id,
+                            expires: new Date().getTime() + muteTime * 1000
+                        }
+                    );
                 }
             }
-        } catch { errors++; }
+        } catch {
+            errors++;
+        }
         try {
             if (config.moderation.mute.role !== null) {
                 await member.roles.add(config.moderation.mute.role);
-                await client.database.eventScheduler.schedule("unmuteRole", new Date().getTime() + muteTime * 1000, {
-                    guild: interaction.guild.id,
-                    user: user.id,
-                    role: config.moderation.mute.role
-                });
+                await client.database.eventScheduler.schedule(
+                    "unmuteRole",
+                    new Date().getTime() + muteTime * 1000,
+                    {
+                        guild: interaction.guild.id,
+                        user: user.id,
+                        role: config.moderation.mute.role
+                    }
+                );
             }
-        } catch (e){ console.log(e); errors++; }
+        } catch (e) {
+            console.log(e);
+            errors++;
+        }
         if (errors === 2) {
-            await interaction.editReply({embeds: [new EmojiEmbed()
-                .setEmoji("PUNISH.MUTE.RED")
-                .setTitle("Mute")
-                .setDescription("Something went wrong and the user was not muted")
-                .setStatus("Danger")
-            ], components: []}); // TODO: make this clearer
+            await interaction.editReply({
+                embeds: [
+                    new EmojiEmbed()
+                        .setEmoji("PUNISH.MUTE.RED")
+                        .setTitle("Mute")
+                        .setDescription(
+                            "Something went wrong and the user was not muted"
+                        )
+                        .setStatus("Danger")
+                ],
+                components: []
+            }); // TODO: make this clearer
             if (dmd) await dm.delete();
             return;
         }
-        await client.database.history.create("mute", interaction.guild.id, member.user, interaction.user, reason);
-        const failed = (dmd === false && notify);
-        await interaction.editReply({embeds: [new EmojiEmbed()
-            .setEmoji(`PUNISH.MUTE.${failed ? "YELLOW" : "GREEN"}`)
-            .setTitle("Mute")
-            .setDescription("The member was muted" + (failed ? ", but could not be notified" : "") + (confirmation.components.appeal.response ? ` and an appeal ticket was opened in <#${confirmation.components.appeal.response}>` : ""))
-            .setStatus(failed ? "Warning" : "Success")
-        ], components: []});
+        await client.database.history.create(
+            "mute",
+            interaction.guild.id,
+            member.user,
+            interaction.user,
+            reason
+        );
+        const failed = !dmd && notify;
+        await interaction.editReply({
+            embeds: [
+                new EmojiEmbed()
+                    .setEmoji(`PUNISH.MUTE.${failed ? "YELLOW" : "GREEN"}`)
+                    .setTitle("Mute")
+                    .setDescription(
+                        "The member was muted" +
+                            (failed ? ", but could not be notified" : "") +
+                            (confirmation.components.appeal.response
+                                ? ` and an appeal ticket was opened in <#${confirmation.components.appeal.response}>`
+                                : "")
+                    )
+                    .setStatus(failed ? "Warning" : "Success")
+            ],
+            components: []
+        });
         const data = {
-            meta:{
+            meta: {
                 type: "memberMute",
                 displayName: "Member Muted",
                 calculateType: "guildMemberPunish",
@@ -223,9 +422,18 @@
             list: {
                 memberId: entry(member.user.id, `\`${member.user.id}\``),
                 name: entry(member.user.id, renderUser(member.user)),
-                mutedUntil: entry(new Date().getTime() + muteTime * 1000, renderDelta(new Date().getTime() + muteTime * 1000)),
-                muted: entry(new Date().getTime(), renderDelta(new Date().getTime() - 1000)),
-                mutedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
+                mutedUntil: entry(
+                    new Date().getTime() + muteTime * 1000,
+                    renderDelta(new Date().getTime() + muteTime * 1000)
+                ),
+                muted: entry(
+                    new Date().getTime(),
+                    renderDelta(new Date().getTime() - 1000)
+                ),
+                mutedBy: entry(
+                    interaction.member.user.id,
+                    renderUser(interaction.member.user)
+                ),
                 reason: entry(reason, reason ? reason : "*No reason provided*")
             },
             hidden: {
@@ -234,39 +442,49 @@
         };
         log(data);
     } else {
-        await interaction.editReply({embeds: [new EmojiEmbed()
-            .setEmoji("PUNISH.MUTE.GREEN")
-            .setTitle("Mute")
-            .setDescription("No changes were made")
-            .setStatus("Success")
-        ], components: []});
+        await interaction.editReply({
+            embeds: [
+                new EmojiEmbed()
+                    .setEmoji("PUNISH.MUTE.GREEN")
+                    .setTitle("Mute")
+                    .setDescription("No changes were made")
+                    .setStatus("Success")
+            ],
+            components: []
+        });
     }
 };
 
 const check = (interaction: CommandInteraction) => {
-    const member = (interaction.member as GuildMember);
-    const me = (interaction.guild.me as GuildMember);
-    const apply = (interaction.options.getMember("user") as GuildMember);
-    if (member === null || me === null || apply === null) throw "That member is not in the server";
+    const member = interaction.member as GuildMember;
+    const me = interaction.guild.me!;
+    const apply = interaction.options.getMember("user") as GuildMember;
+    if (member === null || me === null || apply === null)
+        throw "That member is not in the server";
     const memberPos = member.roles ? member.roles.highest.position : 0;
     const mePos = me.roles ? me.roles.highest.position : 0;
     const applyPos = apply.roles ? apply.roles.highest.position : 0;
     // Do not allow muting the owner
-    if (member.id === interaction.guild.ownerId) throw "You cannot mute the owner of the server";
+    if (member.id === interaction.guild.ownerId)
+        throw "You cannot mute the owner of the server";
     // Check if Nucleus can mute the member
-    if (! (mePos > applyPos)) throw "I do not have a role higher than that member";
+    if (!(mePos > applyPos))
+        throw "I do not have a role higher than that member";
     // Check if Nucleus has permission to mute
-    if (! me.permissions.has("MODERATE_MEMBERS")) throw "I do not have the *Moderate Members* permission";
+    if (!me.permissions.has("MODERATE_MEMBERS"))
+        throw "I do not have the *Moderate Members* permission";
     // Do not allow muting Nucleus
     if (member.id === me.id) throw "I cannot mute myself";
     // Allow the owner to mute anyone
     if (member.id === interaction.guild.ownerId) return true;
     // Check if the user has moderate_members permission
-    if (! member.permissions.has("MODERATE_MEMBERS")) throw "You do not have the *Moderate Members* permission";
+    if (!member.permissions.has("MODERATE_MEMBERS"))
+        throw "You do not have the *Moderate Members* permission";
     // Check if the user is below on the role list
-    if (! (memberPos > applyPos)) throw "You do not have a role higher than that member";
+    if (!(memberPos > applyPos))
+        throw "You do not have a role higher than that member";
     // Allow mute
     return true;
 };
 
-export { command, callback, check };
\ No newline at end of file
+export { command, callback, check };
