diff --git a/src/commands/mod/mute.ts b/src/commands/mod/mute.ts
index 327ecdf..2b01ffc 100644
--- a/src/commands/mod/mute.ts
+++ b/src/commands/mod/mute.ts
@@ -1,10 +1,11 @@
 import { LoadingEmbed } from "./../../utils/defaultEmbeds.js";
 import Discord, { CommandInteraction, GuildMember, Message, MessageActionRow, MessageButton } from "discord.js";
-import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
 import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
 import getEmojiByName from "../../utils/getEmojiByName.js";
 import confirmationMessage from "../../utils/confirmationMessage.js";
 import keyValueList from "../../utils/generateKeyValueList.js";
+// @ts-expect-error
 import humanizeDuration from "humanize-duration";
 import client from "../../utils/client.js";
 import { areTicketsEnabled, create } from "../../actions/createModActionTicket.js";
@@ -56,7 +57,7 @@
         minutes: interaction.options.getInteger("minutes") ?? 0,
         seconds: interaction.options.getInteger("seconds") ?? 0
     };
-    const config = await client.database.guilds.read(interaction.guild.id);
+    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 +=
@@ -158,13 +159,13 @@
         });
     }
     // TODO:[Modals] Replace this with a modal
-    let reason = null;
+    let reason: string | null = null;
     let notify = true;
     let createAppealTicket = false;
     let confirmation;
     let timedOut = false;
     let success = false;
-    while (!timedOut && !success) {
+    do {
         confirmation = await new confirmationMessage(interaction)
             .setEmoji("PUNISH.MUTE.RED")
             .setTitle("Mute")
@@ -174,7 +175,7 @@
                     time: `${humanizeDuration(muteTime * 1000, {
                         round: true
                     })}`,
-                    reason: reason ? "\n> " + (reason ?? "").replaceAll("\n", "\n> ") : "*No reason provided*"
+                    reason: reason ? "\n> " + (reason).replaceAll("\n", "\n> ") : "*No reason provided*"
                 }) +
                     "The user will be " +
                     serverSettingsDescription +
@@ -186,9 +187,9 @@
             .addCustomBoolean(
                 "appeal",
                 "Create appeal ticket",
-                !(await areTicketsEnabled(interaction.guild.id)),
+                !(await areTicketsEnabled(interaction.guild!.id)),
                 async () =>
-                    await create(interaction.guild, interaction.options.getUser("user"), interaction.user, reason),
+                    await create(interaction.guild!, interaction.options.getUser("user")!, interaction.user, reason),
                 "An appeal ticket will be created when Confirm is clicked",
                 "CONTROL.TICKET",
                 createAppealTicket
@@ -197,7 +198,7 @@
                 "notify",
                 "Notify user",
                 false,
-                null,
+                undefined,
                 null,
                 "ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
                 notify
@@ -209,154 +210,165 @@
         if (confirmation.success) success = true;
         if (confirmation.newReason) reason = confirmation.newReason;
         if (confirmation.components) {
-            notify = confirmation.components.notify.active;
-            createAppealTicket = confirmation.components.appeal.active;
+            notify = confirmation.components["notify"]!.active;
+            createAppealTicket = confirmation.components["appeal"]!.active;
         }
-    }
+    } while (!timedOut && !success)
     if (timedOut) return;
     let dmd = false;
     let dm;
-    const config = await client.database.guilds.read(interaction.guild.id);
-    try {
-        if (notify) {
-            dm = await user.send({
+    if (confirmation.success) {
+        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")
+                    ],
+                    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;
+        }
+        const member = user;
+        let errors = 0;
+        try {
+            if (config.moderation.mute.timeout) {
+                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
+                    });
+                }
+            }
+        } 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
+                });
+            }
+        } catch (e) {
+            console.log(e);
+            errors++;
+        }
+        if (errors === 2) {
+            await interaction.editReply({
                 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}>`
-                                    : "")
-                        )
+                        .setTitle("Mute")
+                        .setDescription("Something went wrong and the user was not muted")
                         .setStatus("Danger")
                 ],
-                components: [
-                    new MessageActionRow().addComponents(
-                        config.moderation.mute.text
-                            ? [
-                                  new MessageButton()
-                                      .setStyle("LINK")
-                                      .setLabel(config.moderation.mute.text)
-                                      .setURL(config.moderation.mute.link)
-                              ]
-                            : []
-                    )
-                ]
-            });
-            dmd = true;
+                components: []
+            }); // TODO: make this clearer
+            if (dmd && dm) await dm.delete();
+            return;
         }
-    } catch {
-        dmd = false;
-    }
-    const member = user;
-    let errors = 0;
-    try {
-        if (config.moderation.mute.timeout) {
-            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
-                });
-            }
-        }
-    } 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
-            });
-        }
-    } catch (e) {
-        console.log(e);
-        errors++;
-    }
-    if (errors === 2) {
+        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.RED")
+                    .setEmoji(`PUNISH.MUTE.${failed ? "YELLOW" : "GREEN"}`)
                     .setTitle("Mute")
-                    .setDescription("Something went wrong and the user was not muted")
-                    .setStatus("Danger")
+                    .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: []
-        }); // TODO: make this clearer
-        if (dmd) await dm.delete();
-        return;
+        });
+        const data = {
+            meta: {
+                type: "memberMute",
+                displayName: "Member Muted",
+                calculateType: "guildMemberPunish",
+                color: NucleusColors.yellow,
+                emoji: "PUNISH.WARN.YELLOW",
+                timestamp: new Date().getTime()
+            },
+            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)),
+                reason: entry(reason, reason ? reason : "*No reason provided*")
+            },
+            hidden: {
+                guild: interaction.guild!.id
+            }
+        };
+        log(data);
+    } else {
+        await interaction.editReply({
+            embeds: [
+                new EmojiEmbed()
+                    .setEmoji("PUNISH.BAN.GREEN")
+                    .setTitle("Softban")
+                    .setDescription("No changes were made")
+                    .setStatus("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: {
-            type: "memberMute",
-            displayName: "Member Muted",
-            calculateType: "guildMemberPunish",
-            color: NucleusColors.yellow,
-            emoji: "PUNISH.WARN.YELLOW",
-            timestamp: new Date().getTime()
-        },
-        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)),
-            reason: entry(reason, reason ? reason : "*No reason provided*")
-        },
-        hidden: {
-            guild: interaction.guild.id
-        }
-    };
-    log(data);
 };
 
 const check = (interaction: CommandInteraction) => {
     const member = interaction.member as GuildMember;
-    const me = interaction.guild.me!;
+    const me = interaction.guild!.me!;
     const apply = interaction.options.getMember("user") as GuildMember;
-    if (member === null || me === null || apply === null) throw new Error("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;
+    const memberPos = member.roles.cache.size > 1 ? member.roles.highest.position : 0;
+    const mePos = me.roles.cache.size > 1 ? me.roles.highest.position : 0;
+    const applyPos = apply.roles.cache.size > 1 ? apply.roles.highest.position : 0;
     // Do not allow muting the owner
-    if (member.id === interaction.guild.ownerId) throw new Error("You cannot mute the owner of the server");
+    if (member.id === interaction.guild!.ownerId) throw new Error("You cannot mute the owner of the server");
     // Check if Nucleus can mute the member
     if (!(mePos > applyPos)) throw new Error("I do not have a role higher than that member");
     // Check if Nucleus has permission to mute
@@ -364,7 +376,7 @@
     // Do not allow muting Nucleus
     if (member.id === me.id) throw new Error("I cannot mute myself");
     // Allow the owner to mute anyone
-    if (member.id === interaction.guild.ownerId) return true;
+    if (member.id === interaction.guild!.ownerId) return true;
     // Check if the user has moderate_members permission
     if (!member.permissions.has("MODERATE_MEMBERS"))
         throw new Error("You do not have the *Moderate Members* permission");
