diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts
index 08fcc77..60b90e3 100644
--- a/src/events/interactionCreate.ts
+++ b/src/events/interactionCreate.ts
@@ -8,49 +8,123 @@
 
 export const event = "interactionCreate";
 
-
 function getAutocomplete(typed: string, options: string[]): object[] {
-    options = options.filter(option => option.length <= 100); // thanks discord. 6000 character limit on slash command inputs but only 100 for autocomplete.
-    if (!typed) return options.slice(0, 25).sort().map(option => ({name: option, value: option}));
-    const fuse = new Fuse(options, {useExtendedSearch: true, findAllMatches: true, minMatchCharLength: 0}).search(typed);
-    return fuse.slice(0, 25).map(option => ({name: option.item, value: option.item}));
+    options = options.filter((option) => option.length <= 100); // thanks discord. 6000 character limit on slash command inputs but only 100 for autocomplete.
+    if (!typed)
+        return options
+            .slice(0, 25)
+            .sort()
+            .map((option) => ({ name: option, value: option }));
+    const fuse = new Fuse(options, {
+        useExtendedSearch: true,
+        findAllMatches: true,
+        minMatchCharLength: 0
+    }).search(typed);
+    return fuse
+        .slice(0, 25)
+        .map((option) => ({ name: option.item, value: option.item }));
 }
 
 function generateStatsChannelAutocomplete(typed) {
-    const validReplacements = ["serverName", "memberCount", "memberCount:bots", "memberCount:humans"];
+    const validReplacements = [
+        "serverName",
+        "memberCount",
+        "memberCount:bots",
+        "memberCount:humans"
+    ];
     const autocompletions = [];
     const beforeLastOpenBracket = typed.match(/(.*){[^{}]{0,15}$/);
-    if (beforeLastOpenBracket !== null) { for (const replacement of validReplacements) { autocompletions.push(`${beforeLastOpenBracket[1]} {${replacement}}`); } }
-    else { for (const replacement of validReplacements) { autocompletions.push(`${typed} {${replacement}}`); } }
+    if (beforeLastOpenBracket !== null) {
+        for (const replacement of validReplacements) {
+            autocompletions.push(
+                `${beforeLastOpenBracket[1]} {${replacement}}`
+            );
+        }
+    } else {
+        for (const replacement of validReplacements) {
+            autocompletions.push(`${typed} {${replacement}}`);
+        }
+    }
     return getAutocomplete(typed, autocompletions);
 }
 function generateWelcomeMessageAutocomplete(typed) {
-    const validReplacements = ["serverName", "memberCount", "memberCount:bots", "memberCount:humans", "member:mention", "member:name"];
+    const validReplacements = [
+        "serverName",
+        "memberCount",
+        "memberCount:bots",
+        "memberCount:humans",
+        "member:mention",
+        "member:name"
+    ];
     const autocompletions = [];
     const beforeLastOpenBracket = typed.match(/(.*){[^{}]{0,15}$/);
-    if (beforeLastOpenBracket !== null) { for (const replacement of validReplacements) { autocompletions.push(`${beforeLastOpenBracket[1]} {${replacement}}`); } }
-    else { for (const replacement of validReplacements) { autocompletions.push(`${typed} {${replacement}}`); } }
+    if (beforeLastOpenBracket !== null) {
+        for (const replacement of validReplacements) {
+            autocompletions.push(
+                `${beforeLastOpenBracket[1]} {${replacement}}`
+            );
+        }
+    } else {
+        for (const replacement of validReplacements) {
+            autocompletions.push(`${typed} {${replacement}}`);
+        }
+    }
     return getAutocomplete(typed, autocompletions);
 }
 
 async function interactionCreate(interaction) {
     if (interaction.componentType === "BUTTON") {
         switch (interaction.customId) {
-        case "rolemenu": { return await roleMenu(interaction); }
-        case "verifybutton": { return verify(interaction); }
-        case "createticket": { return create(interaction); }
-        case "closeticket": { return close(interaction); }
-        case "createtranscript": { return createTranscript(interaction); }
+            case "rolemenu": {
+                return await roleMenu(interaction);
+            }
+            case "verifybutton": {
+                return verify(interaction);
+            }
+            case "createticket": {
+                return create(interaction);
+            }
+            case "closeticket": {
+                return close(interaction);
+            }
+            case "createtranscript": {
+                return createTranscript(interaction);
+            }
         }
     } else if (interaction.type === "APPLICATION_COMMAND_AUTOCOMPLETE") {
-        switch (`${interaction.commandName} ${interaction.options.getSubcommandGroup(false)} ${interaction.options.getSubcommand(false)}`) {
-        case "tag null null": { return interaction.respond(getAutocomplete(interaction.options.getString("tag"), (await tagAutocomplete(interaction)))); }
-        case "settings null stats": { return interaction.respond(generateStatsChannelAutocomplete(interaction.options.getString("name"))); }
-        case "settings null welcome": { return interaction.respond(generateWelcomeMessageAutocomplete(interaction.options.getString("message"))); }
+        switch (
+            `${
+                interaction.commandName
+            } ${interaction.options.getSubcommandGroup(
+                false
+            )} ${interaction.options.getSubcommand(false)}`
+        ) {
+            case "tag null null": {
+                return interaction.respond(
+                    getAutocomplete(
+                        interaction.options.getString("tag"),
+                        await tagAutocomplete(interaction)
+                    )
+                );
+            }
+            case "settings null stats": {
+                return interaction.respond(
+                    generateStatsChannelAutocomplete(
+                        interaction.options.getString("name")
+                    )
+                );
+            }
+            case "settings null welcome": {
+                return interaction.respond(
+                    generateWelcomeMessageAutocomplete(
+                        interaction.options.getString("message")
+                    )
+                );
+            }
         }
     }
 }
 
 export async function callback(client, interaction) {
     await interactionCreate(interaction);
-}
\ No newline at end of file
+}
