diff --git a/src/actions/createModActionTicket.ts b/src/actions/createModActionTicket.ts
new file mode 100644
index 0000000..0162523
--- /dev/null
+++ b/src/actions/createModActionTicket.ts
@@ -0,0 +1,94 @@
+import Discord, { MessageActionRow, MessageButton } from 'discord.js';
+import EmojiEmbed from '../utils/generateEmojiEmbed.js';
+import getEmojiByName from "../utils/getEmojiByName.js";
+import client from "../utils/client.js";
+
+export async function create(guild: Discord.Guild, member: Discord.User, createdBy: Discord.User, reason: string) {
+    let config = await client.database.guilds.read(guild.id);
+    // @ts-ignore
+    const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger
+    let overwrites = [{
+        id: member,
+        allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
+        type: "member"
+    }] as Discord.OverwriteResolvable[];
+    overwrites.push({
+        id: guild.roles.everyone,
+        deny: ["VIEW_CHANNEL"],
+        type: "role"
+    })
+    if (config.tickets.supportRole != null) {
+        overwrites.push({
+            id: guild.roles.cache.get(config.tickets.supportRole),
+            allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
+            type: "role"
+        })
+    }
+
+    let c;
+    try {
+        c = await guild.channels.create(member.username, {
+            type: "GUILD_TEXT",
+            topic: `${member.id} Active`,
+            parent: config.tickets.category,
+            nsfw: false,
+            permissionOverwrites: (overwrites as Discord.OverwriteResolvable[]),
+            reason: "Creating ticket"
+        })
+    } catch (e) {
+        return null
+    }
+    try {
+        await c.send(
+            {
+                content: (`<@${member.id}>` + (config.tickets.supportRole != null ? ` • <@&${config.tickets.supportRole}>` : "")),
+                allowedMentions: {
+                    users: [member.id],
+                    roles: (config.tickets.supportRole != null ? [config.tickets.supportRole] : [])
+                }
+            }
+        )
+        await c.send({ embeds: [new EmojiEmbed()
+            .setTitle("New Ticket")
+            .setDescription(
+                `Ticket created by a Moderator\n` +
+                `**Support type:** Appeal submission\n` + (reason != null ? `**Reason:**\n> ${reason}\n` : "") +
+                `**Ticket ID:** \`${c.id}\`\n` +
+                `Type \`/ticket close\` to close this ticket.`,
+            )
+            .setStatus("Success")
+            .setEmoji("GUILD.TICKET.OPEN")
+        ], components: [new MessageActionRow().addComponents([new MessageButton()
+            .setLabel("Close")
+            .setStyle("DANGER")
+            .setCustomId("closeticket")
+            .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+        ])]})
+        let data = {
+            meta:{
+                type: 'ticketCreate',
+                displayName: 'Ticket Created',
+                calculateType: "ticketUpdate",
+                color: NucleusColors.green,
+                emoji: 'GUILD.TICKET.OPEN',
+                timestamp: new Date().getTime()
+            },
+            list: {
+                ticketFor: entry(member.id, renderUser(member)),
+                createdBy: entry(createdBy.id, renderUser(createdBy)),
+                created: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+                ticketChannel: entry(c.id, renderChannel(c)),
+            },
+            hidden: {
+                guild: guild.id
+            }
+        }
+        log(data);
+    } catch (e) { console.log(e); return null }
+    return c.id
+}
+
+export async function areTicketsEnabled(guild: string) {
+    let config = await client.database.guilds.read(guild);
+    return config.tickets.enabled;
+}
\ No newline at end of file
diff --git a/src/actions/roleMenu.ts b/src/actions/roleMenu.ts
new file mode 100644
index 0000000..a4397a3
--- /dev/null
+++ b/src/actions/roleMenu.ts
@@ -0,0 +1,157 @@
+import { Message, MessageButton } from "discord.js";
+import EmojiEmbed from '../utils/generateEmojiEmbed.js'
+import { MessageActionRow, MessageSelectMenu } from 'discord.js';
+import getEmojiByName from "../utils/getEmojiByName.js";
+import client from "../utils/client.js";
+
+export async function callback(interaction) {
+    let config = await client.database.guilds.read(interaction.guild.id);
+    if (!config.roleMenu.enabled) return await interaction.reply({embeds: [new EmojiEmbed()
+        .setTitle("Roles")
+        .setDescription("Self roles are currently disabled. Please contact a staff member or try again later.")
+        .setStatus("Danger")
+        .setEmoji("CONTROL.BLOCKCROSS")
+    ], ephemeral: true})
+    if (config.roleMenu.options.length === 0) return await interaction.reply({embeds: [new EmojiEmbed()
+        .setTitle("Roles")
+        .setDescription("There are no roles available. Please contact a staff member or try again later.")
+        .setStatus("Danger")
+        .setEmoji("CONTROL.BLOCKCROSS")
+    ], ephemeral: true})
+    await interaction.reply({embeds: [new EmojiEmbed()
+        .setTitle("Roles")
+        .setDescription("Loading...")
+        .setStatus("Success")
+        .setEmoji("NUCLEUS.LOADING")
+    ], ephemeral: true})
+    let m;
+    if (config.roleMenu.allowWebUI) {
+        let code = ""
+        let length = 5
+        let itt = 0
+        const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+        while (true) {
+            itt += 1
+            code = ""
+            for (let i = 0; i < length; i++) { code += chars.charAt(Math.floor(Math.random() * chars.length)); }
+            if (code in client.roleMenu) continue;
+            if (itt > 1000) {
+                itt = 0
+                length += 1
+                continue;
+            }
+            break;
+        }
+        client.roleMenu[code] = {
+            guild: interaction.guild.id,
+            guildName: interaction.guild.name,
+            guildIcon: interaction.guild.iconURL({format: "png"}),
+            user: interaction.member.user.id,
+            username: interaction.member.user.username,
+            data: config.roleMenu.options,
+            interaction: interaction
+        };
+        let up = true
+        try {
+            let status = await fetch(client.config.baseUrl).then(res => res.status);
+            if (status != 200) up = false
+        } catch { up = false }
+        m = await interaction.editReply({
+            embeds: [new EmojiEmbed()
+                .setTitle("Roles")
+                .setDescription("Select how to choose your roles")
+                .setStatus("Success")
+                .setEmoji("GUILD.GREEN")
+            ], components: [new MessageActionRow().addComponents([
+                new MessageButton()
+                    .setLabel("Online")
+                    .setStyle("LINK")
+                    .setDisabled(!up)
+                    .setURL(`${client.config.baseUrl}/nucleus/rolemenu?code=${code}`),
+                new MessageButton()
+                    .setLabel("Manual")
+                    .setStyle("PRIMARY")
+                    .setCustomId("manual")
+            ])]
+        })
+    }
+    let component;
+    try { component = await (m as Message).awaitMessageComponent({time: 300000});
+    } catch (e) { return }
+    component.deferUpdate()
+    let rolesToAdd = []
+    for (let i = 0; i < config.roleMenu.options.length; i++) {
+        let object = config.roleMenu.options[i];
+        let m = await interaction.editReply({
+            embeds: [
+                new EmojiEmbed()
+                    .setTitle("Roles")
+                    .setEmoji("GUILD.GREEN")
+                    .setDescription(`**${object.name}**` + (object.description ? `\n${object.description}` : ``) +
+                        `\n\nSelect ${object.min}` + (object.min != object.max ? ` to ${object.max}` : ``) + ` role${object.max == 1 ? '' : 's'} to add.`)
+                    .setStatus("Success")
+                    .setFooter({text: `Step ${i + 1}/${config.roleMenu.options.length}`})
+            ],
+            components: [
+                new MessageActionRow().addComponents([
+                    new MessageButton()
+                        .setLabel("Cancel")
+                        .setStyle("DANGER")
+                        .setCustomId("cancel")
+                        .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+                    ].concat(object.min == 0 ? [
+                        new MessageButton()
+                            .setLabel("Skip")
+                            .setStyle("SECONDARY")
+                            .setCustomId("skip")
+                            .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
+                        ] : []))
+            ].concat([new MessageActionRow().addComponents([new MessageSelectMenu()
+                .setPlaceholder(`${object.name}`)
+                .setCustomId("rolemenu")
+                .setMinValues(object.min)
+                .setMaxValues(object.max)
+                .setOptions(object.options.map(o => { return {label: o.name, description: o.description, value: o.role} }))
+            ])])
+        });
+        let component;
+        try {
+            component = await (m as Message).awaitMessageComponent({time: 300000});
+        } catch (e) {
+            return
+        }
+        component.deferUpdate()
+        if (component.customId == "rolemenu") {
+            rolesToAdd = rolesToAdd.concat(component.values)
+        } else if (component.customId == "cancel") {
+            return await interaction.editReply({embeds: [new EmojiEmbed()
+                .setTitle("Roles")
+                .setDescription("Cancelled. No changes were made.")
+                .setStatus("Danger")
+                .setEmoji("GUILD.RED")
+            ], components: []})
+        }
+    }
+    let rolesToRemove = config.roleMenu.options.map(o => o.options.map(o => o.role)).flat()
+    let memberRoles = interaction.member.roles.cache.map(r => r.id)
+    rolesToRemove = rolesToRemove.filter(r => memberRoles.includes(r)).filter(r => !rolesToAdd.includes(r))
+    rolesToAdd = rolesToAdd.filter(r => !memberRoles.includes(r))
+    try {
+        await interaction.member.roles.remove(rolesToRemove)
+        await interaction.member.roles.add(rolesToAdd)
+    } catch (e) {
+        return await interaction.reply({embeds: [new EmojiEmbed()
+            .setTitle("Roles")
+            .setDescription("Something went wrong and your roles were not added. Please contact a staff member or try again later.")
+            .setStatus("Danger")
+            .setEmoji("GUILD.RED")
+        ], components: []})
+    }
+    await interaction.editReply({embeds: [new EmojiEmbed()
+        .setTitle("Roles")
+        .setDescription("Roles have been added. You may close this message.")
+        .setStatus("Success")
+        .setEmoji("GUILD.GREEN")
+    ], components: []})
+    return
+}
diff --git a/src/actions/tickets/create.ts b/src/actions/tickets/create.ts
new file mode 100644
index 0000000..e21aa3e
--- /dev/null
+++ b/src/actions/tickets/create.ts
@@ -0,0 +1,206 @@
+import Discord, { MessageActionRow, MessageButton } from "discord.js";
+import { tickets, toHexArray } from "../../utils/calculate.js";
+import client from "../../utils/client.js";
+import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+
+function capitalize(s: string) {
+    s = s.replace(/([A-Z])/g, ' $1');
+    return s.length < 3 ? s.toUpperCase() : s[0].toUpperCase() + s.slice(1).toLowerCase();
+}
+
+export default async function (interaction) {
+    const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger
+
+    let config = await client.database.guilds.read(interaction.guild.id);
+    if (!config.tickets.enabled || !config.tickets.category) {
+        return await interaction.reply({embeds: [new EmojiEmbed()
+            .setTitle("Tickets are disabled")
+            .setDescription("Please enable tickets in the configuration to use this command.")
+            .setStatus("Danger")
+            .setEmoji("CONTROL.BLOCKCROSS")
+        ], ephemeral: true});
+    }
+    let category = interaction.guild.channels.cache.get(config.tickets.category) as Discord.CategoryChannel;
+    let count = 0;
+    category.children.forEach(element => {
+        if (!(element.type == "GUILD_TEXT")) return;
+        if ((element as Discord.TextChannel).topic.includes(`${interaction.member.user.id}`)) {
+            if ((element as Discord.TextChannel).topic.endsWith("Active")) {
+                count++;
+            }
+        }
+    });
+    if (count >= config.tickets.maxTickets) {
+        return await interaction.reply({embeds: [new EmojiEmbed()
+            .setTitle("Create Ticket")
+            .setDescription(`You have reached the maximum amount of tickets (${config.tickets.maxTickets}). Please close one of your active tickets before creating a new one.`)
+            .setStatus("Danger")
+            .setEmoji("CONTROL.BLOCKCROSS")
+        ], ephemeral: true});
+    }
+    let ticketTypes;
+    let custom = false
+    if (config.tickets.customTypes && config.tickets.useCustom) { ticketTypes = config.tickets.customTypes; custom = true }
+    else if (config.tickets.types) ticketTypes = toHexArray(config.tickets.types, tickets);
+    else ticketTypes = [];
+    let chosenType;
+    let splitFormattedTicketTypes = [];
+    if (ticketTypes.length > 0) {
+        let formattedTicketTypes = [];
+        formattedTicketTypes = ticketTypes.map(type => {
+            if (custom) {
+                return new MessageButton()
+                    .setLabel(type)
+                    .setStyle("PRIMARY")
+                    .setCustomId(type)
+            } else {
+                return new MessageButton()
+                    .setLabel(capitalize(type))
+                    .setStyle("PRIMARY")
+                    .setCustomId(type)
+                    .setEmoji(getEmojiByName(("TICKETS." + type.toString().toUpperCase()), "id"));
+            }
+        });
+        for (let i = 0; i < formattedTicketTypes.length; i += 5) {
+            splitFormattedTicketTypes.push(new MessageActionRow().addComponents(formattedTicketTypes.slice(i, i + 5)));
+        }
+        let m = await interaction.reply({embeds: [new EmojiEmbed()
+            .setTitle("Create Ticket")
+            .setDescription("Select a ticket type")
+            .setStatus("Success")
+            .setEmoji("GUILD.TICKET.OPEN")
+        ], ephemeral: true, fetchReply: true, components: splitFormattedTicketTypes});
+        let component;
+        try {
+            component = await (m as Discord.Message).awaitMessageComponent({time: 300000});
+        } catch (e) {
+            return;
+        }
+        chosenType = component.customId;
+        splitFormattedTicketTypes = [];
+        formattedTicketTypes = [];
+        formattedTicketTypes = ticketTypes.map(type => {
+            if (custom) {
+                return new MessageButton()
+                    .setLabel(type)
+                    .setStyle(chosenType == type ? "SUCCESS" : "SECONDARY")
+                    .setCustomId(type)
+                    .setDisabled(true)
+                } else {
+                    return new MessageButton()
+                    .setLabel(capitalize(type))
+                    .setStyle(chosenType == type ? "SUCCESS" : "SECONDARY")
+                    .setCustomId(type)
+                    .setEmoji(getEmojiByName(("TICKETS." + type.toString().toUpperCase()), "id"))
+                    .setDisabled(true)
+            }
+        });
+        for (let i = 0; i < formattedTicketTypes.length; i += 5) {
+            splitFormattedTicketTypes.push(new MessageActionRow().addComponents(formattedTicketTypes.slice(i, i + 5)));
+        }
+        component.update({embeds: [new EmojiEmbed()
+            .setTitle("Create Ticket")
+            .setDescription("Select a ticket type")
+            .setStatus("Success")
+            .setEmoji("GUILD.TICKET.OPEN")
+        ], components: splitFormattedTicketTypes});
+    } else {
+        chosenType = null
+        await interaction.reply({embeds: [new EmojiEmbed()
+            .setTitle("Create Ticket")
+            .setEmoji("GUILD.TICKET.OPEN")
+        ], ephemeral: true, components: splitFormattedTicketTypes})
+    }
+    let overwrites = [{
+        id: interaction.member,
+        allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
+        type: "member"
+    }] as Discord.OverwriteResolvable[];
+    overwrites.push({
+        id: interaction.guild.roles.everyone,
+        deny: ["VIEW_CHANNEL"],
+        type: "role"
+    })
+    if (config.tickets.supportRole != null) {
+        overwrites.push({
+            id: interaction.guild.roles.cache.get(config.tickets.supportRole),
+            allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
+            type: "role"
+        })
+    }
+
+    let c;
+    try {
+        c = await interaction.guild.channels.create(interaction.member.user.username, {
+            type: "GUILD_TEXT",
+            topic: `${interaction.member.user.id} Active`,
+            parent: config.tickets.category,
+            nsfw: false,
+            permissionOverwrites: (overwrites as Discord.OverwriteResolvable[]),
+            reason: "Creating ticket"
+        })
+    } catch (e) {
+        return await interaction.editReply({embeds: [new EmojiEmbed()
+            .setTitle("Create Ticket")
+            .setDescription("Failed to create ticket")
+            .setStatus("Danger")
+            .setEmoji("CONTROL.BLOCKCROSS")
+        ]});
+    }
+    try {
+        await c.send(
+            {
+                content: (`<@${interaction.member.user.id}>` + (config.tickets.supportRole != null ? ` • <@&${config.tickets.supportRole}>` : "")),
+                allowedMentions: {
+                    users: [(interaction.member as Discord.GuildMember).id],
+                    roles: (config.tickets.supportRole != null ? [config.tickets.supportRole] : [])
+                }
+            }
+        )
+        let content = interaction.options ? interaction.options.getString("message") || "" : "";
+        if (content) content = `**Message:**\n> ${content}\n`;
+        let emoji = custom ? "" : getEmojiByName("TICKETS." + chosenType.toUpperCase());
+        await c.send({ embeds: [new EmojiEmbed()
+            .setTitle("New Ticket")
+            .setDescription(
+                `Ticket created by <@${interaction.member.user.id}>\n` +
+                `**Support type:** ${chosenType != null ? (emoji) + " " + capitalize(chosenType) : "General"}\n` +
+                `**Ticket ID:** \`${c.id}\`\n${content}\n` +
+                `Type \`/ticket close\` to close this ticket.`,
+            )
+            .setStatus("Success")
+            .setEmoji("GUILD.TICKET.OPEN")
+        ], components: [new MessageActionRow().addComponents([new MessageButton()
+            .setLabel("Close")
+            .setStyle("DANGER")
+            .setCustomId("closeticket")
+            .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+        ])]})
+        let data = {
+            meta:{
+                type: 'ticketCreate',
+                displayName: 'Ticket Created',
+                calculateType: "ticketUpdate",
+                color: NucleusColors.green,
+                emoji: 'GUILD.TICKET.OPEN',
+                timestamp: new Date().getTime()
+            },
+            list: {
+                ticketFor: entry(interaction.member.user.id, renderUser(interaction.member.user)),
+                created: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+                ticketChannel: entry(c.id, renderChannel(c)),
+            },
+            hidden: {
+                guild: interaction.guild.id
+            }
+        }
+        log(data);
+    } catch (e) { console.log(e)}
+    await interaction.editReply({embeds: [new EmojiEmbed()
+        .setTitle("Create Ticket")
+        .setDescription(`Ticket created. You can view it here: <#${c.id}>`)
+        .setStatus("Success")
+        .setEmoji("GUILD.TICKET.OPEN")
+    ], components: splitFormattedTicketTypes});
+}
\ No newline at end of file
diff --git a/src/actions/tickets/delete.ts b/src/actions/tickets/delete.ts
new file mode 100644
index 0000000..1985a08
--- /dev/null
+++ b/src/actions/tickets/delete.ts
@@ -0,0 +1,163 @@
+import Discord, { MessageButton, MessageActionRow } from "discord.js";
+import client from "../../utils/client.js";
+import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+
+export default async function (interaction) {
+    const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger
+
+    let config = await client.database.guilds.read(interaction.guild.id);
+    let thread = false; let threadChannel
+    if (interaction.channel instanceof Discord.ThreadChannel) thread = true; threadChannel = interaction.channel as Discord.ThreadChannel
+    let channel = (interaction.channel as Discord.TextChannel)
+    if (!channel.parent || config.tickets.category != channel.parent.id || (thread ? (threadChannel.parent.parent.id != config.tickets.category) : false)) {
+        return interaction.reply({embeds: [new EmojiEmbed()
+            .setTitle("Deleting Ticket...")
+            .setDescription("This ticket is not in your tickets category, so cannot be deleted. You cannot run close in a thread.")
+            .setStatus("Danger")
+            .setEmoji("CONTROL.BLOCKCROSS")
+        ], ephemeral: true});
+    }
+    let status = channel.topic.split(" ")[1];
+    if (status == "Archived") {
+        await interaction.reply({embeds: [new EmojiEmbed()
+            .setTitle("Delete Ticket")
+            .setDescription("Your ticket is being deleted...")
+            .setStatus("Danger")
+            .setEmoji("GUILD.TICKET.CLOSE")
+        ]});
+        let data = {
+            meta:{
+                type: 'ticketDeleted',
+                displayName: 'Ticket Deleted',
+                calculateType: "ticketUpdate",
+                color: NucleusColors.red,
+                emoji: 'GUILD.TICKET.CLOSE',
+                timestamp: new Date().getTime()
+            },
+            list: {
+                ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
+                deletedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
+                deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
+            },
+            hidden: {
+                guild: interaction.guild.id
+            }
+        }
+        log(data);
+        interaction.channel.delete();
+        return;
+    } else if (status == "Active") {
+        await interaction.reply({embeds: [new EmojiEmbed()
+            .setTitle("Close Ticket")
+            .setDescription("Your ticket is being closed...")
+            .setStatus("Warning")
+            .setEmoji("GUILD.TICKET.ARCHIVED")
+        ]});
+        let overwrites = [
+            {
+                id: channel.topic.split(" ")[0],
+                deny: ["VIEW_CHANNEL"],
+                type: "member"
+            },
+            {
+                id: interaction.guild.id,
+                deny: ["VIEW_CHANNEL"],
+                type: "role"
+            }
+        ] as Discord.OverwriteResolvable[];
+        if (config.tickets.supportRole != null) {
+            overwrites.push({
+                id: interaction.guild.roles.cache.get(config.tickets.supportRole),
+                allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
+                type: "role"
+            })
+        }
+        channel.edit({permissionOverwrites: overwrites})
+        channel.setTopic(`${channel.topic.split(" ")[0]} Archived`);
+        let data = {
+            meta:{
+                type: 'ticketClosed',
+                displayName: 'Ticket Closed',
+                calculateType: "ticketUpdate",
+                color: NucleusColors.yellow,
+                emoji: 'GUILD.TICKET.ARCHIVED',
+                timestamp: new Date().getTime()
+            },
+            list: {
+                ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
+                closedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
+                closed: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+                ticketChannel: entry(channel.id, renderChannel(channel)),
+            },
+            hidden: {
+                guild: interaction.guild.id
+            }
+        }
+        log(data);
+        await interaction.editReply({embeds: [new EmojiEmbed()
+            .setTitle("Close Ticket")
+            .setDescription("This ticket has been closed.\nType `/ticket close` again to delete it.\n\nNote: Check `/privacy` for details about transcripts.")
+            .setStatus("Warning")
+            .setEmoji("GUILD.TICKET.ARCHIVED")
+        ], components: [
+            new MessageActionRow().addComponents([
+                new MessageButton()
+                    .setLabel("Delete")
+                    .setStyle("DANGER")
+                    .setCustomId("closeticket")
+                    .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+                ].concat(client.database.premium.hasPremium(interaction.guild.id) ? [
+                    new MessageButton()
+                    .setLabel("Create Transcript and Delete")
+                    .setStyle("PRIMARY")
+                    .setCustomId("createtranscript")
+                    .setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
+            ] : []))
+        ]});
+        return;
+    }
+}
+
+async function purgeByUser(member, guild) {
+    let config = await client.database.guilds.read(guild.id);
+    if (!config.tickets.category) return;
+    let tickets = guild.channels.cache.get(config.tickets.category);
+    if (!tickets) return;
+    let ticketChannels = tickets.children;
+    let deleted = 0
+    ticketChannels.forEach(element => {
+        if (element.type != "GUILD_TEXT") return;
+        if (element.topic.split(" ")[0] == member) {
+            try { element.delete(); } catch {}
+            deleted++
+        }
+    });
+    if (deleted) {
+        try {
+            const { log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger
+            let data = {
+                meta:{
+                    type: 'ticketPurge',
+                    displayName: 'Tickets Purged',
+                    calculateType: "ticketUpdate",
+                    color: NucleusColors.red,
+                    emoji: 'GUILD.TICKET.DELETE',
+                    timestamp: new Date().getTime()
+                },
+                list: {
+                    ticketFor: entry(member, renderUser(member)),
+                    deletedBy: entry(null, "Member left server"),
+                    deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+                    ticketsDeleted: deleted,
+                },
+                hidden: {
+                    guild: guild.id
+                }
+            }
+            log(data);
+        } catch {}
+    }
+}
+
+export { purgeByUser }
\ No newline at end of file
