diff --git a/src/commands/categorisationTest.ts b/src/commands/categorisationTest.ts
new file mode 100644
index 0000000..2852a2b
--- /dev/null
+++ b/src/commands/categorisationTest.ts
@@ -0,0 +1,75 @@
+import { CommandInteraction, MessageActionRow, MessageButton, MessageSelectMenu } from "discord.js";
+import { SelectMenuComponent, SelectMenuOption, SlashCommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+import generateEmojiEmbed from "../utils/generateEmojiEmbed.js";
+import generateKeyValueList, { toCapitals } from "../utils/generateKeyValueList.js";
+import getEmojiByName from "../utils/getEmojiByName.js";
+
+const command = new SlashCommandBuilder()
+    .setName("categorise")
+    .setDescription("Categorises your servers channels")
+
+const callback = async (interaction: CommandInteraction) => {
+    // @ts-ignore
+    const { renderChannel } = interaction.client.logger
+
+    let channels = interaction.guild.channels.cache.filter(c => c.type !== "GUILD_CATEGORY");
+    let categorised = {}
+
+    await interaction.reply({embeds: [new generateEmojiEmbed()
+        .setTitle("Loading...")
+        .setEmoji("NUCLEUS.LOADING")
+        .setStatus("Success")
+    ], ephemeral: true});
+    for (let c of channels.values()) {
+        let predicted = []
+        let types = {
+            general: ["general"],
+            commands: ["bot", "command", "music"],
+            images: ["pic", "selfies", "image"],
+            nsfw: ["porn", "nsfw", "sex"],
+            links: ["links"],
+            advertising: ["ads", "advert", "server", "partner"],
+            staff: ["staff", "mod", "admin"]
+        }
+
+        for (let type in types) {
+            for (let word of types[type]) {
+                if (c.name.toLowerCase().includes(word)) {
+                    predicted.push(type)
+                }
+            }
+        }
+
+        await interaction.editReply({embeds: [new generateEmojiEmbed()
+            .setTitle("Categorise")
+            .setDescription(generateKeyValueList({
+                channel: renderChannel(c),
+                category: c.parent ? c.parent.name : "Uncategorised"
+            }) + "\n\n" + `Suggested tags: ${predicted.join(", ")}`)
+            .setEmoji("CHANNEL.TEXT.CREATE")
+            .setStatus("Success")
+        ], components: [ new MessageActionRow().addComponents([
+            new MessageButton()
+                .setLabel("Use suggested")
+                .setStyle("PRIMARY")
+                .setCustomId("accept")
+                .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
+        ]), new MessageActionRow().addComponents([new MessageSelectMenu()
+            .setPlaceholder("Select a category")
+            .setCustomId("category")
+            .setMinValues(0)
+            .setMaxValues(1)
+            // .setMaxValues(Object.keys(types).length)
+            .setOptions(Object.keys(types).map(type => {return {label: toCapitals(type), value: type}}))
+        ])]});
+    }
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+    return true;
+}
+
+export { command };
+export { callback };
+export { check };
\ No newline at end of file
diff --git a/src/commands/createTestButton.ts b/src/commands/createTestButton.ts
new file mode 100644
index 0000000..71f9ef1
--- /dev/null
+++ b/src/commands/createTestButton.ts
@@ -0,0 +1,35 @@
+import { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
+import { SlashCommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+
+const command = new SlashCommandBuilder()
+    .setName("createtestbutton")
+    .setDescription("creates a test button")
+
+const callback = (interaction: CommandInteraction) => {
+    interaction.reply({components: [new MessageActionRow().addComponents([
+        new MessageButton()
+            .setCustomId("createticket")
+            .setLabel("Create Ticket")
+            .setStyle("PRIMARY")
+            .setDisabled(false),
+        new MessageButton()
+            .setCustomId("verifybutton")
+            .setLabel("Verify")
+            .setStyle("PRIMARY")
+            .setDisabled(false),
+        new MessageButton()
+            .setCustomId("rolemenu")
+            .setLabel("Get roles")
+            .setStyle("PRIMARY")
+            .setDisabled(false)
+    ])]});
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+    return true;
+}
+
+export { command };
+export { callback };
+export { check };
\ No newline at end of file
diff --git a/src/commands/mod/unnamed.ts b/src/commands/mod/unnamed.ts
new file mode 100644
index 0000000..2d65a87
--- /dev/null
+++ b/src/commands/mod/unnamed.ts
@@ -0,0 +1,233 @@
+import Discord, { CommandInteraction, GuildMember, MessageActionRow } from "discord.js";
+import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+import confirmationMessage from "../../utils/confirmationMessage.js";
+import keyValueList from "../../utils/generateKeyValueList.js";
+import humanizeDuration from "humanize-duration";
+import { create, areTicketsEnabled } from "../../automations/createModActionTicket.js";
+import readConfig from '../../utils/readConfig.js'
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+    builder
+    .setName("unnamed")
+    .setDescription("Gives a user a role")
+    .addUserOption(option => option.setName("user").setDescription("The user to UNNAMED").setRequired(true)) // TODO
+    .addIntegerOption(option => option.setName("days").setDescription("The number of days to UNNAMED the user for | Default 0").setMinValue(0).setMaxValue(27).setRequired(false))
+    .addIntegerOption(option => option.setName("hours").setDescription("The number of hours to UNNAMED the user for | Default 0").setMinValue(0).setMaxValue(23).setRequired(false))
+    .addIntegerOption(option => option.setName("minutes").setDescription("The number of minutes to UNNAMED the user for | Default 0").setMinValue(0).setMaxValue(59).setRequired(false))
+    .addIntegerOption(option => option.setName("seconds").setDescription("The number of seconds to UNNAMED the user for | Default 0").setMinValue(0).setMaxValue(59).setRequired(false))
+    .addStringOption(option => option.setName("reason").setDescription("The reason for the UNNAMED").setRequired(false))
+    .addStringOption(option => option.setName("notify").setDescription("If the user should get a message when they are UNNAMED | Default yes").setRequired(false)
+        .addChoices([["Yes", "yes"], ["No", "no"]]))
+
+const callback = async (interaction: CommandInteraction) => {
+    // @ts-ignore
+    const { log, NucleusColors, renderUser, entry } = interaction.client.logger
+    let config = await readConfig(interaction.guild.id);
+    const user = interaction.options.getMember("user") as GuildMember
+    const reason = interaction.options.getString("reason")
+    const time = {
+        days: interaction.options.getInteger("days") || 0,
+        hours: interaction.options.getInteger("hours") || 0,
+        minutes: interaction.options.getInteger("minutes") || 0,
+        seconds: interaction.options.getInteger("seconds") || 0
+    }
+    let muteTime = (time.days * 24 * 60 * 60) + (time.hours * 60 * 60) + (time.minutes * 60) + time.seconds
+    if (muteTime == 0) {
+        let m = await interaction.reply({embeds: [
+            new generateEmojiEmbed()
+                .setEmoji("PUNISH.MUTE.GREEN") // TODO
+                .setTitle("UNNAMED")
+                .setDescription("How long should the user be UNNAMED")
+                .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})
+        let component;
+        try {
+            component = await (m as Discord.Message).awaitMessageComponent({filter: (m) => m.user.id === interaction.user.id, time: 2.5 * 60 * 1000});
+        } catch { return }
+        component.deferUpdate();
+        if (component.customId == "cancel") return interaction.editReply({embeds: [new generateEmojiEmbed()
+            .setEmoji("PUNISH.MUTE.RED") // TODO
+            .setTitle("UNNAMED")
+            .setDescription("UNNAMED 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; }
+        }
+    } else {
+        await interaction.reply({embeds: [
+            new generateEmojiEmbed()
+                .setEmoji("PUNISH.MUTE.GREEN") // TODO
+                .setTitle("UNNAMED")
+                .setDescription("Loading...")
+                .setStatus("Success")
+        ], ephemeral: true, fetchReply: true})
+    }
+    // TODO:[Modals] Replace this with a modal
+    let confirmation = await new confirmationMessage(interaction)
+        .setEmoji("PUNISH.MUTE.RED") // TODO
+        .setTitle("UNNAMED")
+        .setDescription(keyValueList({
+            "user": `<@!${user.id}> (${user.user.username})`,
+            "time": `${humanizeDuration(muteTime * 1000, {round: true})}`,
+            "reason": `\n> ${reason ? reason : "*No reason provided*"}`
+        })
+        + `The user **will${interaction.options.getString("notify") === "no" ? ' not' : ''}** be notified\n\n`
+        + `Are you sure you want to mute <@!${(interaction.options.getMember("user") as GuildMember).id}>?`) // TODO
+        .setColor("Danger")
+        .addCustomCallback(
+            "Create appeal ticket", !(await areTicketsEnabled(interaction.guild.id)),
+            () => { create(interaction.guild, interaction.options.getUser("user"), interaction.client)},
+            "An appeal ticket was created")
+//        pluralize("day", interaction.options.getInteger("delete"))
+//        const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" }
+    .send()
+    if (confirmation.success) {
+        let dmd = false
+        let dm;
+        try {
+            if (interaction.options.getString("notify") != "no") {
+                dm = await (interaction.options.getMember("user") as GuildMember).send({
+                    embeds: [new generateEmojiEmbed()
+                        .setEmoji("PUNISH.MUTE.RED") // TODO
+                        .setTitle("UNNAMED")
+                        .setDescription(`You have been muted in ${interaction.guild.name}` + // TODO
+                                    (interaction.options.getString("reason") ? ` for:\n> ${interaction.options.getString("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>)`)) // TODO
+                        .setStatus("Danger")
+                    ]
+                })
+                dmd = true
+            }
+        } catch {}
+        try {
+            await ((interaction.options.getMember("user") as GuildMember).roles.add(interaction.guild.roles.cache.find((r) => r.id === config.moderation.role.role)))
+            // TODO: Store when to remove the role
+        } catch {
+            await interaction.editReply({embeds: [new generateEmojiEmbed()
+                .setEmoji("PUNISH.MUTE.RED")
+                .setTitle(`Mute`)
+                .setDescription("Something went wrong and the user was not UNNAMED")
+                .setStatus("Danger")
+            ], components: []})
+            if (dmd) await dm.delete()
+            return
+        }
+        let failed = (dmd == false && interaction.options.getString("notify") != "no")
+        await interaction.editReply({embeds: [new generateEmojiEmbed()
+            .setEmoji(`PUNISH.MUTE.${failed ? "YELLOW" : "GREEN"}`) // TODO
+            .setTitle(`Mute`) // TODO
+            .setDescription("The member was muted" + (failed ? ", but could not be notified" : "")) // TODO
+            .setStatus(failed ? "Warning" : "Success")
+        ], components: []})
+        let data = {
+            meta:{
+                type: 'memberMute', // TODO
+                displayName: 'Member Muted', // TODO
+                calculateType: 'guildMemberPunish',
+                color: NucleusColors.yellow,
+                emoji: 'PUNISH.WARN.YELLOW', // TODO
+                timestamp: new Date().getTime()
+            },
+            list: {
+                user: entry((interaction.options.getMember("user") as GuildMember).user.id, renderUser((interaction.options.getMember("user") as GuildMember).user)),
+                mutedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)), // TODO
+                time: entry(muteTime, `${humanizeDuration(muteTime * 1000, {round: true})}`),
+                reason: (interaction.options.getString("reason") ? `\n> ${interaction.options.getString("reason")}` : "No reason provided")
+            },
+            hidden: {
+                guild: interaction.guild.id
+            }
+        }
+        log(data, interaction.client);
+    } else {
+        await interaction.editReply({embeds: [new generateEmojiEmbed()
+            .setEmoji("PUNISH.MUTE.GREEN") // TODO
+            .setTitle(`Mute`) // TODO
+            .setDescription("No changes were made")
+            .setStatus("Success")
+        ], components: []})
+    }
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+    let member = (interaction.member as GuildMember)
+    let me = (interaction.guild.me as GuildMember)
+    let apply = (interaction.options.getMember("user") as GuildMember)
+    if (member == null || me == null || apply == null) throw "That member is not in the server"
+    let memberPos = member.roles ? member.roles.highest.position : 0
+    let mePos = me.roles ? me.roles.highest.position : 0
+    let applyPos = apply.roles ? apply.roles.highest.position : 0
+    // Check if Nucleus can UNNAMED the member
+    if (! (mePos > applyPos)) throw "I do not have a role higher than that member"
+    // Check if Nucleus has permission to UNNAMED
+    if (! interaction.guild.me.permissions.has("MANAGE_ROLES")) throw "I do not have the `manage_roles` permission";
+    // Do not allow the user to have admin or be the owner
+    if ((interaction.options.getMember("user") as GuildMember).permissions.has("ADMINISTRATOR") || (interaction.options.getMember("user") as GuildMember).id == interaction.guild.ownerId) throw "You cannot mute an admin or the owner"
+    // Do not allow muting Nucleus
+    if ((interaction.member as GuildMember).id == interaction.guild.me.id) throw "I cannot UNNAMED myself"
+    // Allow the owner to UNNAMED anyone
+    if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+    // Check if the user has moderate_members permission
+    if (! (interaction.member as GuildMember).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"
+    // Allow UNNAMED
+    return true
+}
+
+export { command, callback, check };
\ No newline at end of file
diff --git a/src/commands/nucleus/guide.ts b/src/commands/nucleus/guide.ts
new file mode 100644
index 0000000..814d2f5
--- /dev/null
+++ b/src/commands/nucleus/guide.ts
@@ -0,0 +1,24 @@
+import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
+import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import guide from "../../automations/guide.js";
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+    builder
+    .setName("guide")
+    .setDescription("Shows the welcome guide for the bot")
+
+
+const callback = async (interaction) => {
+    guide(interaction.guild, interaction)
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+    return true
+}
+
+export { command };
+export { callback };
+export { check };
diff --git a/src/commands/nucleus/invite.ts b/src/commands/nucleus/invite.ts
new file mode 100644
index 0000000..44934e1
--- /dev/null
+++ b/src/commands/nucleus/invite.ts
@@ -0,0 +1,30 @@
+import { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
+import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+    builder
+    .setName("invite")
+    .setDescription("Invites Nucleus to your server")
+
+const callback = (interaction: CommandInteraction) => {
+    interaction.reply({embeds: [new generateEmojiEmbed()
+        .setTitle("Invite")
+        .setDescription("You can invite Nucleus to your server by clicking the button below")
+        .setEmoji("NUCLEUS.LOGO")
+        .setStatus("Danger")
+    ], components: [new MessageActionRow().addComponents([new MessageButton()
+        .setLabel("Invite")
+        .setStyle("LINK")
+        .setURL(`https://discord.com/api/oauth2/authorize?client_id=${interaction.client.user.id}&permissions=295157886134&scope=bot%20applications.commands`)
+    ])], ephemeral: true});
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+    return true;
+}
+
+export { command };
+export { callback };
+export { check };
\ No newline at end of file
diff --git a/src/commands/server/_meta.ts b/src/commands/server/_meta.ts
new file mode 100644
index 0000000..379aac6
--- /dev/null
+++ b/src/commands/server/_meta.ts
@@ -0,0 +1,4 @@
+const name = "server";
+const description = "Commands for the server";
+
+export { name, description };
\ No newline at end of file
diff --git a/src/commands/server/about.ts b/src/commands/server/about.ts
new file mode 100644
index 0000000..054cad3
--- /dev/null
+++ b/src/commands/server/about.ts
@@ -0,0 +1,50 @@
+import Discord, { CommandInteraction, Guild, MessageActionRow, MessageButton } from "discord.js";
+import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+import generateKeyValueList, { toCapitals } from "../../utils/generateKeyValueList.js";
+
+const command = (builder: SlashCommandSubcommandBuilder) => builder
+    .setName("about")
+    .setDescription("Shows info about the server")
+
+const callback = async (interaction: CommandInteraction) => {
+    let guild = interaction.guild as Guild;
+    // @ts-ignore
+    const { renderUser, renderDelta } = interaction.client.logger
+    interaction.reply({embeds: [new generateEmojiEmbed()
+        .setTitle("Server Info")
+        .setStatus("Success")
+        .setEmoji("GUILD.GREEN")
+        .setDescription(
+            generateKeyValueList({
+                "name": guild.name,
+                "id": `\`${guild.id}\``,
+                "owner": `${renderUser((await guild.fetchOwner()).user)}`,
+                "created": `${renderDelta(guild.createdTimestamp)}`,
+                "emojis": `${guild.emojis.cache.size}` + (guild.emojis.cache.size > 1 ? `\n> ${
+                        guild.emojis.cache.first(10).map((emoji) => `<${emoji.animated ? 'a' : ''}:${emoji.name}:${emoji.id}>`).join(" ")
+                    }` +
+                    (guild.emojis.cache.size > 10 ? ` and ${guild.emojis.cache.size - 10} more` : ``) : ""),
+                "icon": `[Discord](${guild.iconURL()})`,
+                "2 factor authentication": `${guild.mfaLevel === "NONE" ? `${getEmojiByName("CONTROL.CROSS")} No` : `${getEmojiByName("CONTROL.TICK")} Yes`}`,
+                "verification level": `${toCapitals(guild.verificationLevel)}`,
+                "explicit content filter": `${toCapitals(guild.explicitContentFilter.toString().replace(/_/, " ", ))}`,
+                "nitro boost level": `${guild.premiumTier != "NONE" ? guild.premiumTier.toString()[-1] : "0"}`,
+                "channels": `${guild.channels.cache.size}`,
+                "roles": `${guild.roles.cache.size}`,
+                "members": `${guild.memberCount}`,
+            })
+        )
+        .setThumbnail(guild.iconURL({dynamic: true}))
+    ], ephemeral: true});
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+    return true;
+}
+
+export { command };
+export { callback };
+export { check };
\ No newline at end of file
diff --git a/src/commands/user/track.ts b/src/commands/user/track.ts
new file mode 100644
index 0000000..da6a37a
--- /dev/null
+++ b/src/commands/user/track.ts
@@ -0,0 +1,174 @@
+import Discord, { CommandInteraction, GuildMember, Message, MessageActionRow, MessageButton } from "discord.js";
+import { SelectMenuOption, SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+import generateKeyValueList from "../../utils/generateKeyValueList.js";
+import readConfig from "../../utils/readConfig.js";
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+    builder
+    .setName("track")
+    .setDescription("Moves a user along a role track")
+    .addUserOption(option => option.setName("user").setDescription("The user to manage").setRequired(true))
+
+const generateFromTrack = (position: number, active: any, size: number, disabled: any) => {
+    active = active ? "ACTIVE" : "INACTIVE"
+    disabled = disabled ? "GREY." : ""
+    if (position == 0 && size == 1) return "TRACKS.SINGLE." + disabled + active
+    if (position == size - 1) return "TRACKS.VERTICAL.BOTTOM." + disabled + active
+    if (position == 0) return "TRACKS.VERTICAL.TOP." + disabled + active
+    return "TRACKS.VERTICAL.MIDDLE." + disabled + active
+}
+
+const callback = async (interaction: CommandInteraction) => {
+    // @ts-ignore
+    const { renderUser } = interaction.client.logger
+    const member = interaction.options.getMember("user") as GuildMember;
+    const guild = interaction.guild;
+    let config = await readConfig(guild.id);
+    await interaction.reply({embeds: [new generateEmojiEmbed()
+        .setEmoji("NUCLEUS.LOADING")
+        .setTitle("Loading")
+        .setStatus("Danger")
+    ], ephemeral: true})
+    let track = 0
+    let generated;
+    const roles = await guild.roles.fetch()
+    let memberRoles = await member.roles
+    while (true) {
+        let data = config.tracks[track]
+        let managed = data.manageableBy.some(element => {return memberRoles.cache.has(element)})
+        let dropdown = new Discord.MessageSelectMenu().addOptions(config.tracks.map((option, index) => {
+            let hasRoleInTrack = option.track.some(element => {return memberRoles.cache.has(element)})
+            return new SelectMenuOption({
+                default: index == track,
+                label: option.name,
+                value: index.toString(),
+                description: option.track.length == 0 ? "No" : option.track.length + " role" + (option.track.length == 1 ? "" : "s"), // TODO[s addition]
+                emoji: interaction.client.emojis.resolve(getEmojiByName("TRACKS.SINGLE." + (hasRoleInTrack ? "ACTIVE" : "INACTIVE"), "id"))
+            })
+        })).setCustomId("select").setMaxValues(1)
+        let allowed = []
+        generated = "**Track:** " + data.name + "\n" + "**Member:** " + renderUser(member.user) + "\n"
+        generated += (data.nullable ? "Members do not need a role in this track" : "A role in this track is required") + "\n"
+        generated += (data.retainPrevious ? "When promoted, the user keeps previous roles" : "Members will lose their current role when promoted") + "\n"
+        generated += "\n" + data.track.map((role, index) => {
+            let allow = (roles.get(role).position >= (interaction.member as GuildMember).roles.highest.position) && !managed
+            allowed.push(!allow)
+            return getEmojiByName(generateFromTrack(
+                index,
+                memberRoles.cache.has(role),
+                data.track.length,
+                allow
+            )) + " " +
+            roles.get(role).name + " [<@&" + roles.get(role).id + ">]"
+        }).join("\n")
+        let selected = [];
+        for (let i = 0; i < data.track.length; i++) {
+            if (memberRoles.cache.has(data.track[i])) selected.push(data.track[i])
+        }
+        let conflict = data.retainPrevious ? false : selected.length > 1;
+        let conflictDropdown
+        let currentRoleIndex
+        if (conflict) {
+            generated += `\n\n${getEmojiByName(`PUNISH.WARN.${managed ? "YELLOW" : "RED"}`)} This user has ${selected.length} roles from this track. `
+            conflictDropdown = []
+            if (
+                (roles.get(selected[0]).position < memberRoles.highest.position) || managed
+            ) {
+                generated +=  `In order to promote or demote this user, you must select which role the member should keep.`
+                selected.forEach(role => {
+                    conflictDropdown.push(new SelectMenuOption({
+                        label: roles.get(role).name,
+                        value: roles.get(role).id,
+                    }))
+                })
+                conflictDropdown = [new Discord.MessageSelectMenu()
+                    .addOptions(conflictDropdown)
+                    .setCustomId("conflict")
+                    .setMaxValues(1)
+                    .setPlaceholder("Select a role to keep")]
+            } else {
+                generated += "You don't have permission to manage one or more of the users roles, and therefore can't select one to keep."
+            }
+        } else {
+            currentRoleIndex = selected.length == 0 ? -1 : data.track.indexOf(selected[0].toString())
+        }
+        let m = await interaction.editReply({embeds: [new generateEmojiEmbed()
+            .setEmoji("TRACKS.ICON")
+            .setTitle("Tracks")
+            .setDescription(`${generated}`)
+            .setStatus("Success")
+        ], components: [
+            new MessageActionRow().addComponents(dropdown)
+        ]
+        .concat(conflict && conflictDropdown.length ? [new MessageActionRow().addComponents(conflictDropdown)] : [])
+        .concat([
+            new MessageActionRow().addComponents([
+                new MessageButton()
+                    .setEmoji(getEmojiByName("CONTROL.UP", "id"))
+                    .setLabel("Move up")
+                    .setCustomId("promote")
+                    .setStyle("SUCCESS")
+                    .setDisabled(conflict || currentRoleIndex == 0 || (currentRoleIndex == -1 ? false : !allowed[currentRoleIndex - 1])),
+                new MessageButton()
+                    .setEmoji(getEmojiByName("CONTROL.DOWN", "id"))
+                    .setLabel("Move down")
+                    .setCustomId("demote")
+                    .setStyle("DANGER")
+                    .setDisabled(conflict || (
+                        data.nullable ? currentRoleIndex <= -1 :
+                        currentRoleIndex == data.track.length - 1 || currentRoleIndex <= -1
+                    ) || !allowed[currentRoleIndex]),
+            ])
+        ])})
+        let component;
+        try {
+            component = await (m as Message).awaitMessageComponent({time: 2.5 * 60 * 1000});
+        } catch (e) {
+            return
+        }
+        component.deferUpdate()
+        if (component.customId == "conflict") {
+            let rolesToRemove = selected.filter(role => role != component.values[0])
+            await member.roles.remove(rolesToRemove)
+        } else if (component.customId == "promote") {
+            if (
+                currentRoleIndex == -1 ? allowed[data.track.length - 1] :
+                allowed[currentRoleIndex - 1] && allowed[currentRoleIndex]
+            ) {
+                if (currentRoleIndex == -1) {
+                    await member.roles.add(data.track[data.track.length - 1])
+                } else if (currentRoleIndex < data.track.length) {
+                    if (!data.retainPrevious) await member.roles.remove(data.track[currentRoleIndex])
+                    await member.roles.add(data.track[currentRoleIndex - 1])
+                }
+            }
+        } else if (component.customId == "demote") {
+            if(allowed[currentRoleIndex]) {
+                if (currentRoleIndex == data.track.length - 1) {
+                    if (data.nullable) await member.roles.remove(data.track[currentRoleIndex])
+                } else if (currentRoleIndex > -1) {
+                    await member.roles.remove(data.track[currentRoleIndex])
+                    await member.roles.add(data.track[currentRoleIndex + 1])
+                }
+            }
+        } else if (component.customId == "select") {
+            track = component.values[0]
+        }
+    }
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+    // Allow the owner to promote anyone
+    if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+    // Check if the user has manage_roles permission
+    if (! (interaction.member as GuildMember).permissions.has("MANAGE_ROLES")) throw "You do not have the `manage_roles` permission";
+    // Allow track
+    return true // TODO: allow if the member has manage perms
+}
+
+export { command };
+export { callback };
+export { check };
\ No newline at end of file
