diff --git a/src/commands/settings/tickets.ts b/src/commands/settings/tickets.ts
index 64dc980..aac271e 100644
--- a/src/commands/settings/tickets.ts
+++ b/src/commands/settings/tickets.ts
@@ -1,24 +1,410 @@
-import { CommandInteraction } from "discord.js";
-import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import confirmationMessage from "../../utils/confirmationMessage.js";
+import Discord, { CommandInteraction, MessageActionRow, MessageButton, MessageSelectMenu, TextInputComponent } from "discord.js";
+import { SelectMenuOption, SlashCommandSubcommandBuilder } from "@discordjs/builders";
 import { WrappedCheck } from "jshaiku";
 import { ChannelType } from 'discord-api-types';
+import client from "../../utils/client.js";
+import { toHexInteger, toHexArray, tickets as ticketTypes } from "../../utils/calculate.js";
+import { capitalize } from '../../utils/generateKeyValueList.js';
+import { modalInteractionCollector } from "../../utils/dualCollector.js";
 
-const command = (builder: SlashCommandSubcommandBuilder) =>
-    builder
+const command = (builder: SlashCommandSubcommandBuilder) => builder
     .setName("tickets")
-    .setDescription("Shows settings for tickets")
-    .addStringOption(option => option.setName("enabled").setDescription("If users should be able to create tickets | Default yes").setRequired(false)
+    .setDescription("Shows settings for tickets | Use no arguments to manage custom types")
+    .addStringOption(option => option.setName("enabled").setDescription("If users should be able to create tickets").setRequired(false)
         .addChoices([["Yes", "yes"], ["No", "no"]]))
     .addChannelOption(option => option.setName("category").setDescription("The category where tickets are created").addChannelType(ChannelType.GuildCategory).setRequired(false))
-    .addNumberOption(option => option.setName("maxtickets").setDescription("The maximum amount of tickets a user can create | Default 5").setRequired(false).setMinValue(1))
-    .addRoleOption(option => option.setName("supportping").setDescription("The role pinged when a ticket is created").setRequired(false))
+    .addNumberOption(option => option.setName("maxticketsperuser").setDescription("The maximum amount of tickets a user can create | Default 5").setRequired(false).setMinValue(1))
+    .addRoleOption(option => option.setName("supportrole").setDescription("This role will have view access to all tickets and will be pinged when a ticket is created").setRequired(false))
 
-const callback = (interaction: CommandInteraction) => {
-    interaction.reply("This command is not yet finished [settings/tickets]");
+const callback = async (interaction: CommandInteraction): Promise<any> => {
+    let m;
+    m = await interaction.reply({
+        embeds: [new generateEmojiEmbed()
+            .setTitle("Loading")
+            .setStatus("Danger")
+            .setEmoji("NUCLEUS.LOADING")
+        ], ephemeral: true, fetchReply: true
+    });
+    let options = {
+        enabled: interaction.options.getString("enabled") as string | boolean,
+        category: interaction.options.getChannel("category"),
+        maxtickets: interaction.options.getNumber("maxticketsperuser"),
+        supportping: interaction.options.getRole("supportrole")
+    }
+    if (options.enabled !== null || options.category || options.maxtickets || options.supportping) {
+        options.enabled = options.enabled === "yes" ? true : false;
+        if (options.category) {
+            let channel
+            try {
+                channel = interaction.guild.channels.cache.get(options.category.id)
+            } catch {
+                return await interaction.editReply({
+                    embeds: [new generateEmojiEmbed()
+                        .setEmoji("CHANNEL.TEXT.DELETE")
+                        .setTitle("Tickets > Category")
+                        .setDescription("The channel you provided is not a valid category")
+                        .setStatus("Danger")
+                    ]
+                })
+            }
+            channel = channel as Discord.CategoryChannel
+            if (channel.guild.id != interaction.guild.id) return interaction.editReply({
+                embeds: [new generateEmojiEmbed()
+                    .setTitle("Tickets > Category")
+                    .setDescription(`You must choose a category in this server`)
+                    .setStatus("Danger")
+                    .setEmoji("CHANNEL.TEXT.DELETE")
+                ]
+            });
+        }
+        if (options.maxtickets) {
+            if (options.maxtickets < 1) return interaction.editReply({
+                embeds: [new generateEmojiEmbed()
+                    .setTitle("Tickets > Max Tickets")
+                    .setDescription(`You must choose a number greater than 0`)
+                    .setStatus("Danger")
+                    .setEmoji("CHANNEL.TEXT.DELETE")
+                ]
+            });
+        }
+        let role
+        if (options.supportping) {
+            try {
+                role = interaction.guild.roles.cache.get(options.supportping.id)
+            } catch {
+                return await interaction.editReply({
+                    embeds: [new generateEmojiEmbed()
+                        .setEmoji("GUILD.ROLE.DELETE")
+                        .setTitle("Tickets > Support Ping")
+                        .setDescription("The role you provided is not a valid role")
+                        .setStatus("Danger")
+                    ]
+                })
+            }
+            role = role as Discord.Role
+            if (role.guild.id != interaction.guild.id) return interaction.editReply({
+                embeds: [new generateEmojiEmbed()
+                    .setTitle("Tickets > Support Ping")
+                    .setDescription(`You must choose a role in this server`)
+                    .setStatus("Danger")
+                    .setEmoji("GUILD.ROLE.DELETE")
+                ]
+            });
+        }
+
+        let confirmation = await new confirmationMessage(interaction)
+            .setEmoji("GUILD.TICKET.ARCHIVED")
+            .setTitle("Tickets")
+            .setDescription(
+                (options.category ? `**Category:** ${options.category.name}\n` : "") +
+                (options.maxtickets ? `**Max Tickets:** ${options.maxtickets}\n` : "") +
+                (options.supportping ? `**Support Ping:** ${options.supportping.name}\n` : "") +
+                (options.enabled !== null ? `**Enabled:** ${options.enabled ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
+                    }\n` : "") +
+                `\nAre you sure you want to apply these settings?`
+            )
+            .setColor("Warning")
+            .setInverted(true)
+            .send(true)
+        if (confirmation.success) {
+            let toUpdate = {}
+            if (options.enabled !== null) toUpdate["tickets.enabled"] = options.enabled
+            if (options.category) toUpdate["tickets.category"] = options.category.id
+            if (options.maxtickets) toUpdate["tickets.maxTickets"] = options.maxtickets
+            if (options.supportping) toUpdate["tickets.supportRole"] = options.supportping.id
+            try {
+                await client.database.write(interaction.guild.id, toUpdate)
+            } catch (e) {
+                return interaction.editReply({
+                    embeds: [new generateEmojiEmbed()
+                        .setTitle("Tickets")
+                        .setDescription(`Something went wrong and the staff notifications channel could not be set`)
+                        .setStatus("Danger")
+                        .setEmoji("GUILD.TICKET.DELETE")
+                    ], components: []
+                });
+            }
+        } else {
+            return interaction.editReply({
+                embeds: [new generateEmojiEmbed()
+                    .setTitle("Tickets")
+                    .setDescription(`No changes were made`)
+                    .setStatus("Success")
+                    .setEmoji("GUILD.TICKET.OPEN")
+                ], components: []
+            });
+        }
+    }
+    let data = await client.database.read(interaction.guild.id);
+    data.tickets.customTypes = data.tickets.customTypes.filter((v, i, a) => a.indexOf(v) === i)
+    let lastClicked = "";
+    let embed;
+    data = {
+        enabled: data.tickets.enabled,
+        category: data.tickets.category,
+        maxTickets: data.tickets.maxTickets,
+        supportRole: data.tickets.supportRole,
+        useCustom: data.tickets.useCustom,
+        types: data.tickets.types,
+        customTypes: data.tickets.customTypes
+    }
+    while (true) {
+        embed = new generateEmojiEmbed()
+            .setTitle("Tickets")
+            .setDescription(
+                `${data.enabled ? "" : getEmojiByName("TICKETS.REPORT")} **Enabled:** ${data.enabled ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`}\n` +
+                `${data.category ? "" : getEmojiByName("TICKETS.REPORT")} **Category:** ${data.category ? `<#${data.category}>` : "*None set*"}\n` +
+                `**Max Tickets:** ${data.maxTickets ? data.maxTickets : "*No limit*"}\n` +
+                `**Support Ping:** ${data.supportRole ? `<@&${data.supportRole}>` : "*None set*"}\n\n` +
+                ((data.useCustom && data.customTypes === null) ? `${getEmojiByName("TICKETS.REPORT")} ` : "") +
+                `${data.useCustom ? "Custom" : "Default"} types in use` + "\n\n" +
+                `${getEmojiByName("TICKETS.REPORT")} *Indicates a setting stopping tickets from being used*`
+            )
+            .setStatus("Success")
+            .setEmoji("GUILD.TICKET.OPEN")
+        m = await interaction.editReply({
+            embeds: [embed], components: [new MessageActionRow().addComponents([
+                new MessageButton()
+                    .setLabel("Tickets " + (data.enabled ? "enabled" : "disabled"))
+                    .setEmoji(getEmojiByName("CONTROL." + (data.enabled ? "TICK" : "CROSS"), "id"))
+                    .setStyle(data.enabled ? "SUCCESS" : "DANGER")
+                    .setCustomId("enabled"),
+                new MessageButton()
+                    .setLabel(lastClicked == "cat" ? "Click again to confirm" : "Clear category")
+                    .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+                    .setStyle("DANGER")
+                    .setCustomId("clearCategory")
+                    .setDisabled(data.category == null),
+                new MessageButton()
+                    .setLabel(lastClicked == "max" ? "Click again to confirm" : "Reset max tickets")
+                    .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+                    .setStyle("DANGER")
+                    .setCustomId("clearMaxTickets")
+                    .setDisabled(data.maxTickets == 5),
+                new MessageButton()
+                    .setLabel(lastClicked == "sup" ? "Click again to confirm" : "Clear support ping")
+                    .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+                    .setStyle("DANGER")
+                    .setCustomId("clearSupportPing")
+                    .setDisabled(data.supportRole == null),
+            ]), new MessageActionRow().addComponents([
+                new MessageButton()
+                    .setLabel("Manage types")
+                    .setEmoji(getEmojiByName("TICKETS.OTHER", "id"))
+                    .setStyle("SECONDARY")
+                    .setCustomId("manageTypes"),
+            ])]
+        });
+        let i;
+        try {
+            i = await m.awaitMessageComponent({ time: 600000 });
+        } catch (e) { break }
+        i.deferUpdate()
+        if (i.component.customId == "clearCategory") {
+            if (lastClicked == "cat") {
+                lastClicked = "";
+                await client.database.write(interaction.guild.id, {}, ["tickets.category"])
+                data.category = undefined;
+            } else lastClicked = "cat";
+        } else if (i.component.customId == "clearMaxTickets") {
+            if (lastClicked == "max") {
+                lastClicked = "";
+                await client.database.write(interaction.guild.id, {}, ["tickets.maxTickets"])
+                data.maxTickets = 5;
+            } else lastClicked = "max";
+        } else if (i.component.customId == "clearSupportPing") {
+            if (lastClicked == "sup") {
+                lastClicked = "";
+                await client.database.write(interaction.guild.id, {}, ["tickets.supportRole"])
+                data.supportRole = undefined;
+            } else lastClicked = "sup";
+        } else if (i.component.customId == "enabled") {
+            await client.database.write(interaction.guild.id, { "tickets.enabled": !data.enabled })
+            data.enabled = !data.enabled;
+        } else if (i.component.customId == "manageTypes") {
+            data = await manageTypes(interaction, data, m);
+        } else {
+            break
+        }
+    }
+    await interaction.editReply({ embeds: [embed.setFooter({ text: "Message closed" })], components: [] });
 }
 
+async function manageTypes(interaction, data, m) {
+    while (true) {
+        if (data.useCustom) {
+            let customTypes = data.customTypes;
+            interaction.editReply({
+                embeds: [new generateEmojiEmbed()
+                    .setTitle("Tickets > Types")
+                    .setDescription(
+                        "**Custom types enabled**\n\n" +
+                        "**Types in use:**\n" + ((customTypes !== null) ?
+                            (customTypes.map((t) => `> ${t}`).join("\n")) :
+                            "*None set*"
+                        ) + "\n\n" + (customTypes === null ?
+                            `${getEmojiByName("TICKETS.REPORT")} Having no types will disable tickets. Please add at least 1 type or use default types` : ""
+                        )
+                    )
+                    .setStatus("Success")
+                    .setEmoji("GUILD.TICKET.OPEN")
+                ], components: (customTypes ? [
+                    new MessageActionRow().addComponents([new Discord.MessageSelectMenu()
+                        .setCustomId("removeTypes")
+                        .setPlaceholder("Select types to remove")
+                        .setMaxValues(customTypes.length)
+                        .setMinValues(1)
+                        .addOptions(customTypes.map((t) => new SelectMenuOption().setLabel(t).setValue(t)))
+                    ])
+                ] : []).concat([
+                    new MessageActionRow().addComponents([
+                        new MessageButton()
+                            .setLabel("Back")
+                            .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
+                            .setStyle("PRIMARY")
+                            .setCustomId("back"),
+                        new MessageButton()
+                            .setLabel("Add new type")
+                            .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id"))
+                            .setStyle("PRIMARY")
+                            .setCustomId("addType")
+                            .setDisabled(customTypes !== null && customTypes.length >= 25),
+                        new MessageButton()
+                            .setLabel("Switch to default types")
+                            .setStyle("SECONDARY")
+                            .setCustomId("switchToDefault"),
+                    ])
+                ])
+            });
+        } else {
+            let inUse = toHexArray(data.types, ticketTypes)
+            let options = [];
+            ticketTypes.forEach(type => {
+                options.push(new SelectMenuOption({
+                    label: capitalize(type),
+                    value: type,
+                    emoji: interaction.client.emojis.cache.get(getEmojiByName(`TICKETS.${type.toUpperCase()}`, "id")),
+                    default: inUse.includes(type)
+                }))
+            })
+            let selectPane = new MessageActionRow().addComponents([
+                new Discord.MessageSelectMenu()
+                    .addOptions(options)
+                    .setCustomId("types")
+                    .setMaxValues(ticketTypes.length)
+                    .setMinValues(1)
+                    .setPlaceholder("Select types to use")
+            ])
+            interaction.editReply({
+                embeds: [new generateEmojiEmbed()
+                    .setTitle("Tickets > Types")
+                    .setDescription(
+                        "**Default types enabled**\n\n" +
+                        "**Types in use:**\n" +
+                        (inUse.map((t) => `> ${getEmojiByName("TICKETS." + t.toUpperCase())} ${capitalize(t)}`).join("\n"))
+                    )
+                    .setStatus("Success")
+                    .setEmoji("GUILD.TICKET.OPEN")
+                ], components: [
+                    selectPane,
+                    new MessageActionRow().addComponents([
+                        new MessageButton()
+                            .setLabel("Back")
+                            .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
+                            .setStyle("PRIMARY")
+                            .setCustomId("back"),
+                        new MessageButton()
+                            .setLabel("Switch to custom types")
+                            .setStyle("SECONDARY")
+                            .setCustomId("switchToCustom"),
+                    ])
+                ]
+            });
+        }
+        let i;
+        try {
+            i = await m.awaitMessageComponent({ time: 600000 });
+        } catch (e) { break }
+        if (i.component.customId == "types") {
+            i.deferUpdate()
+            let types = toHexInteger(i.values, ticketTypes);
+            await client.database.write(interaction.guild.id, { "tickets.types": types })
+            data.types = types;
+        } else if (i.component.customId == "removeTypes") {
+            i.deferUpdate()
+            let types = i.values
+            let customTypes = data.customTypes;
+            if (customTypes) {
+                customTypes = customTypes.filter((t) => !types.includes(t));
+                customTypes = customTypes.length > 0 ? customTypes : null;
+                await client.database.write(interaction.guild.id, { "tickets.customTypes": customTypes })
+                data.customTypes = customTypes;
+            }
+        } else if (i.component.customId == "addType") {
+            await i.showModal(new Discord.Modal().setCustomId("modal").setTitle("Enter a name for the new type").addComponents(
+                // @ts-ignore
+                new MessageActionRow().addComponents(new TextInputComponent()
+                    .setCustomId("type")
+                    .setLabel("Name")
+                    .setMaxLength(100)
+                    .setMinLength(1)
+                    .setPlaceholder("E.g. \"Server Idea\"")
+                    .setRequired(true)
+                    .setStyle("SHORT")
+                )
+            ))
+            await interaction.editReply({
+                embeds: [new generateEmojiEmbed()
+                    .setTitle("Tickets > Types")
+                    .setDescription("Modal opened. If you can't see it, click back and try again.")
+                    .setStatus("Success")
+                    .setEmoji("GUILD.TICKET.OPEN")
+                ], components: [new MessageActionRow().addComponents([new MessageButton()
+                    .setLabel("Back")
+                    .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
+                    .setStyle("PRIMARY")
+                    .setCustomId("back")
+                ])]
+            });
+            let out
+            try {
+                out = await modalInteractionCollector(m, (m) => m.channel.id == interaction.channel.id, (m) => m.customId == "addType")
+            } catch (e) { continue }
+            if (out.fields) {
+                let toAdd = out.fields.getTextInputValue("type");
+                if (!toAdd) { continue }
+                try {
+                    await client.database.append(interaction.guild.id, "tickets.customTypes", toAdd)
+                } catch { continue }
+                data.customTypes = data.customTypes || [];
+                if (!data.customTypes.includes(toAdd)) {
+                    data.customTypes.push(toAdd);
+                }
+            } else { continue }
+        } else if (i.component.customId == "switchToDefault") {
+            i.deferUpdate()
+            await client.database.write(interaction.guild.id, { "tickets.useCustom": false }, [])
+            data.useCustom = false;
+        } else if (i.component.customId == "switchToCustom") {
+            i.deferUpdate()
+            await client.database.write(interaction.guild.id, { "tickets.useCustom": true }, [])
+            data.useCustom = true;
+        } else {
+            i.deferUpdate()
+            break
+        }
+    }
+    return data
+}
+
+
 const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
-    return interaction.memberPermissions.has("MANAGE_GUILD");
+    let member = (interaction.member as Discord.GuildMember)
+    if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the `manage_server` permission to use this command"
+    return true;
 }
 
 export { command };
