diff --git a/src/commands/nucleus/stats.ts b/src/commands/nucleus/stats.ts
index b2658bc..c2bf9a1 100644
--- a/src/commands/nucleus/stats.ts
+++ b/src/commands/nucleus/stats.ts
@@ -21,6 +21,54 @@
 const command = (builder: SlashCommandSubcommandBuilder) =>
     builder.setName("stats").setDescription("Gets the bot's stats");
 
+
+const confirm = async (interaction: CommandInteraction) => {
+    const requiredTexts = [
+        "just do it",
+        "yes, do as i say!",
+        "clicksminuteper/nucleus",
+        "i've said it once i'll say it again",
+        "no, i've changed my mind",
+        "this incident will be reported",
+        "coded told me to",
+        "mini told me to",
+        "pinea told me to",
+        "what's a java script",
+        "it's a feature not a bug",
+        "that never happened during testing"
+    ]
+    const chosen = requiredTexts[Math.floor(Math.random() * (requiredTexts.length - 1))]!;
+
+    const modal = new ModalBuilder()
+            .addComponents(
+                new ActionRowBuilder<TextInputBuilder>().addComponents(
+                    new TextInputBuilder()
+                        .setStyle(TextInputStyle.Short)
+                        .setLabel(`Type "${chosen}" below`)
+                        .setCustomId("confirm")
+                        .setPlaceholder("Guild ID")
+                        .setMinLength(chosen.length)
+                        .setMaxLength(chosen.length)
+                )
+            )
+            .setTitle("Admin Panel")
+            .setCustomId("adminPanel");
+    await interaction.showModal(modal);
+    let out: ModalSubmitInteraction;
+    try {
+        out = await interaction.awaitModalSubmit({
+            filter: (i) => i.customId === "adminPanel" && i.user.id === interaction.user.id,
+            time: 300000
+        });
+    } catch {
+        return;
+    }
+    await out.deferUpdate();
+    const typed = out.fields.getTextInputValue("confirm");
+    return typed.toLowerCase() === chosen.toLowerCase()
+}
+
+
 const callback = async (interaction: CommandInteraction): Promise<void> => {
     const description = `**Servers:** ${client.guilds.cache.size}\n` + `**Ping:** \`${client.ws.ping * 2}ms\``;
     const m = await interaction.reply({
@@ -45,11 +93,7 @@
             ],
             components: [
                 new ActionRowBuilder<ButtonBuilder>().addComponents(
-                    new ButtonBuilder().setCustomId("admin").setLabel("Admin Panel").setStyle(ButtonStyle.Primary),
-                    new ButtonBuilder()
-                        .setCustomId("mod:nickname:599498449733550102")
-                        .setLabel("Testing")
-                        .setStyle(ButtonStyle.Primary)
+                    new ButtonBuilder().setCustomId("admin").setLabel("Admin Panel").setStyle(ButtonStyle.Primary)
                 )
             ]
         });
@@ -77,28 +121,30 @@
             return;
         // console.log(interaction)
         if (!("awaitMessageComponent" in channel)) return;
-        try {
-            i1 = await channel!.awaitMessageComponent<ComponentType.Button>({
-                filter: (i) => i.customId === "admin" && i.user.id === interaction.user.id && i.message.id === m.id,
-                time: 300000
-            });
-        } catch (e) {
-            console.log(e);
-            return;
-        }
-        await i1.showModal(modal);
-        let out: ModalSubmitInteraction;
-        try {
-            out = await i1.awaitModalSubmit({
-                filter: (i) => i.customId === "adminPanel" && i.user.id === interaction.user.id,
-                time: 300000
-            });
-        } catch {
-            return;
-        }
-        await out.deferUpdate();
-        const GuildID = out.fields.getTextInputValue("guildID");
-        if (!client.guilds.cache.has(GuildID)) {
+        let GuildID = interaction.guildId;
+        if (!GuildID) {
+            try {
+                i1 = await channel!.awaitMessageComponent<ComponentType.Button>({
+                    filter: (i) => i.customId === "admin" && i.user.id === interaction.user.id && i.message.id === m.id,
+                    time: 300000
+                });
+            } catch (e) {
+                console.log(e);
+                return;
+            }
+            await i1.showModal(modal);
+            let out: ModalSubmitInteraction;
+            try {
+                out = await i1.awaitModalSubmit({
+                    filter: (i) => i.customId === "adminPanel" && i.user.id === interaction.user.id,
+                    time: 300000
+                });
+            } catch {
+                return;
+            }
+            await out.deferUpdate();
+            GuildID = out.fields.getTextInputValue("guildID");
+        } else if (!client.guilds.cache.has(GuildID)) {
             await interaction.editReply({
                 embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")],
                 components: []
@@ -110,10 +156,10 @@
             components: [
                 new ActionRowBuilder<ButtonBuilder>().addComponents(
                     new ButtonBuilder().setCustomId("stats").setLabel("Stats").setStyle(ButtonStyle.Primary),
-                    new ButtonBuilder().setCustomId("leave").setLabel("Leave").setStyle(ButtonStyle.Danger),
                     new ButtonBuilder().setCustomId("data").setLabel("Guild data").setStyle(ButtonStyle.Secondary),
+                    new ButtonBuilder().setCustomId("cache").setLabel("Reset cache").setStyle(ButtonStyle.Success),
+                    new ButtonBuilder().setCustomId("leave").setLabel("Leave").setStyle(ButtonStyle.Danger),
                     new ButtonBuilder().setCustomId("purge").setLabel("Delete data").setStyle(ButtonStyle.Danger),
-                    new ButtonBuilder().setCustomId("cache").setLabel("Reset cache").setStyle(ButtonStyle.Success)
                 )
             ]
         });
@@ -126,9 +172,9 @@
         } catch {
             return;
         }
-        await i.deferUpdate();
         const guild = (await client.guilds.fetch(GuildID)) as Guild | null;
         if (!guild) {
+            await i.deferUpdate();
             await interaction.editReply({
                 embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")],
                 components: []
@@ -136,66 +182,91 @@
             return;
         }
         if (i.customId === "stats") {
+            await i.deferUpdate();
             await interaction.editReply({
                 embeds: [
                     new EmojiEmbed()
-                        .setTitle("Stats")
-                        .setDescription(
-                            `**Name:** ${guild.name}\n` +
-                                `**ID:** \`${guild.id}\`\n` +
-                                `**Owner:** ${client.users.cache.get(guild.ownerId)!.tag}\n` +
-                                `**Member Count:** ${guild.memberCount}\n` +
-                                `**Created:** <t:${guild.createdTimestamp}:F>\n` +
-                                `**Added Nucleus:** <t:${guild.members.me!.joinedTimestamp}:R>\n` +
-                                `**Nucleus' Perms:** https://discordapi.com/permissions.html#${guild.members.me!.permissions.valueOf()}\n`
+                    .setTitle("Stats")
+                    .setDescription(
+                        `**Name:** ${guild.name}\n` +
+                        `**ID:** \`${guild.id}\`\n` +
+                        `**Owner:** ${client.users.cache.get(guild.ownerId)!.tag}\n` +
+                        `**Member Count:** ${guild.memberCount}\n` +
+                        `**Created:** <t:${guild.createdTimestamp}:F>\n` +
+                        `**Added Nucleus:** <t:${guild.members.me!.joinedTimestamp}:R>\n` +
+                        `**Nucleus' Perms:** https://discordapi.com/permissions.html#${guild.members.me!.permissions.valueOf()}\n`
                         )
                         .setStatus("Success")
                         .setEmoji("SETTINGS.STATS.GREEN")
-                ]
-            });
-        } else if (i.customId === "leave") {
-            await guild.leave();
-            await interaction.editReply({
-                embeds: [
-                    new EmojiEmbed()
+                    ]
+                });
+            } else if (i.customId === "leave") {
+                if (!await confirm(interaction)) {
+                    await interaction.editReply({
+                        embeds: [
+                            new EmojiEmbed()
+                            .setTitle("No changes were made")
+                            .setStatus("Danger")
+                        ],
+                        components: []
+                    });
+                    return;
+                }
+                await guild.leave();
+                await interaction.editReply({
+                    embeds: [
+                        new EmojiEmbed()
                         .setTitle("Left")
                         .setDescription(`Left ${guild.name}`)
                         .setStatus("Success")
                         .setEmoji("SETTINGS.STATS.GREEN")
-                ],
-                components: []
-            });
-        } else if (i.customId === "data") {
-            // Get all the data and convert to a string
-            const data = await client.database.guilds.read(guild.id);
-            const stringified = JSON.stringify(data, null, 2);
-            const buffer = Buffer.from(stringified);
-            const attachment = new AttachmentBuilder(buffer).setName("data.json");
-            await interaction.editReply({
-                embeds: [
-                    new EmojiEmbed().setTitle("Data").setDescription(`Data for ${guild.name}`).setStatus("Success")
-                ],
-                components: [],
-                files: [attachment]
-            });
-        } else if (i.customId === "purge") {
-            await client.database.guilds.delete(GuildID);
-            await client.database.history.delete(GuildID);
-            await client.database.notes.delete(GuildID);
-            await client.database.transcripts.deleteAll(GuildID);
-            await interaction.editReply({
-                embeds: [
-                    new EmojiEmbed()
+                    ],
+                    components: []
+                });
+            } else if (i.customId === "data") {
+                await i.deferUpdate();
+                // Get all the data and convert to a string
+                const data = await client.database.guilds.read(guild.id);
+                const stringified = JSON.stringify(data, null, 2);
+                const buffer = Buffer.from(stringified);
+                const attachment = new AttachmentBuilder(buffer).setName("data.json");
+                await interaction.editReply({
+                    embeds: [
+                        new EmojiEmbed().setTitle("Data").setDescription(`Data for ${guild.name}`).setStatus("Success")
+                    ],
+                    components: [],
+                    files: [attachment]
+                });
+            } else if (i.customId === "purge") {
+                if (!await confirm(interaction)) {
+                    await interaction.editReply({
+                        embeds: [
+                            new EmojiEmbed()
+                            .setTitle("No changes were made")
+                            .setStatus("Danger")
+                        ],
+                        components: []
+                    });
+                    return;
+                }
+                await client.database.guilds.delete(GuildID);
+                await client.database.history.delete(GuildID);
+                await client.database.notes.delete(GuildID);
+                await client.database.transcripts.deleteAll(GuildID);
+                await interaction.editReply({
+                    embeds: [
+                        new EmojiEmbed()
                         .setTitle("Purge")
                         .setDescription(`Deleted data for ${guild.name}`)
                         .setStatus("Success")
                         .setEmoji("SETTINGS.STATS.GREEN")
-                ],
-                components: []
-            });
-        } else if (i.customId === "cache") {
-            await client.memory.forceUpdate(guild.id);
-            await interaction.editReply({
+                    ],
+                    components: []
+                });
+            } else if (i.customId === "cache") {
+                await i.deferUpdate();
+                await client.memory.forceUpdate(guild.id);
+                await interaction.editReply({
                 embeds: [
                     new EmojiEmbed()
                         .setTitle("Cache")
diff --git a/src/commands/nucleus/suggest.ts b/src/commands/nucleus/suggest.ts
index 79a0673..44926c7 100644
--- a/src/commands/nucleus/suggest.ts
+++ b/src/commands/nucleus/suggest.ts
@@ -1,64 +1,115 @@
 import { LoadingEmbed } from "../../utils/defaults.js";
-import { ButtonStyle, CommandInteraction } from "discord.js";
-import Discord from "discord.js";
+import Discord, { ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, ModalBuilder, TextInputBuilder, TextInputStyle } from "discord.js";
 import type { SlashCommandSubcommandBuilder } from "discord.js";
 import confirmationMessage from "../../utils/confirmationMessage.js";
 import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
 import client from "../../utils/client.js";
-import getEmojiByName from "../../utils/getEmojiByName.js";
+import config from "../../config/main.js"
+import _ from "lodash";
 
 const command = (builder: SlashCommandSubcommandBuilder) =>
     builder
         .setName("suggest")
         .setDescription("Sends a suggestion to the developers")
-        .addStringOption((option) =>
-            option.setName("suggestion").setDescription("The suggestion to send").setRequired(true)
-        );
 
 const callback = async (interaction: CommandInteraction): Promise<void> => {
     await interaction.guild?.members.fetch(interaction.member!.user.id);
-    const { renderUser } = client.logger;
-    const suggestion = interaction.options.get("suggestion")?.value as string;
     await interaction.reply({ embeds: LoadingEmbed, ephemeral: true });
-    const confirmation = await new confirmationMessage(interaction)
-        .setEmoji("ICONS.OPP.ADD")
-        .setTitle("Suggest")
-        .setDescription(
-            `**Suggestion:**\n> ${suggestion}\n` +
-                "Your username and ID will also be sent with your suggestion.\n\nAre you sure you want to send this suggestion?"
-        )
-        .setColor("Danger")
-        .setInverted(true)
-        .setFailedMessage("Your suggestion was deleted", "Success", "ICONS.ADD")
-        .send(true);
-    if (confirmation.cancelled || !confirmation.success) return;
-    await (client.channels.cache.get("955161206459600976") as Discord.TextChannel).send({
+    let closed = false;
+    let suggestionTitle: string | null = null
+    let suggestionDesc: string | null = null;
+    do {
+        const modal = new ModalBuilder()
+            .setTitle("Suggestion")
+            .setComponents(
+                new ActionRowBuilder<TextInputBuilder>()
+                    .addComponents(
+                        new TextInputBuilder()
+                            .setLabel("Suggestion Title")
+                            .setRequired(false)
+                            .setStyle(TextInputStyle.Short)
+                            .setCustomId("suggestionTitle")
+                            .setPlaceholder("Summarize your suggestion in 1 sentence...")
+                            .setMaxLength(256)
+                    ),
+                new ActionRowBuilder<TextInputBuilder>()
+                    .addComponents(
+                        new TextInputBuilder()
+                            .setLabel("Suggestion Description")
+                            .setCustomId("suggestionDesc")
+                            .setStyle(TextInputStyle.Paragraph)
+                            .setRequired(true)
+                            .setPlaceholder("Put the full details of your suggestion here...")
+                            .setMinLength(50)
+                    ),
+            )
+        const o: {suggestionDesc?: string, suggestionTitle?: string} = {};
+        if(suggestionTitle) {
+            o.suggestionTitle = suggestionTitle;
+            modal.components[0]!.components[0]!.setValue(suggestionTitle);
+        }
+        if(suggestionDesc) {
+            o.suggestionDesc = suggestionDesc
+            modal.components[1]!.components[0]!.setValue(suggestionDesc);
+        };
+        const confirmation = await new confirmationMessage(interaction)
+            .setEmoji("ICONS.ADD")
+            .setTitle("Suggest")
+            .setDescription(suggestionDesc ? (`Are you sure you want to send this suggestion?\n\n**Title ${suggestionTitle ? "" : "(*Placeholder*)"}:**\n> ${suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}`}\n\n**Suggestion:**\n> ${suggestionDesc}`) : "Please enter your suggestion below.")
+            .addModal("Edit Suggestion", "ICONS.EDIT", "editSuggestion", _.cloneDeep(o), modal)
+            .setColor("Success")
+            .setInverted(true)
+            .setFailedMessage("Your suggestion was deleted", "Success", "ICONS.ADD")
+            .send(true);
+        if(confirmation.modals?.[0] && !_.isEqual(confirmation.modals[0].values, o)) {
+            suggestionTitle = confirmation.modals[0].values["suggestionTitle"] as string | null;
+            suggestionDesc = confirmation.modals[0].values["suggestionDesc"] as string | null;
+            continue;
+        }
+        if(confirmation.cancelled || confirmation.success === false) {
+            closed = true;
+            return;
+        }
+        if (confirmation.success) {
+            closed = true;
+        };
+    } while (!closed);
+    if(!suggestionDesc) return;
+    suggestionTitle = suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}`;
+    const channel = client.channels.cache.get(config.suggestionChannel) as Discord.TextChannel;
+    const m = await channel.send({ embeds: LoadingEmbed});
+    const issue = await client.GitHub.rest.issues.create({
+        owner: "ClicksMinutePer",
+        repo: "Nucleus",
+        title: suggestionTitle,
+        body: `Linked Suggestion in Private Developer Channel: [Message](${m.url})\n\n**Suggestion:**\n> ${
+            suggestionDesc.replaceAll("@", "@<!-- -->").replaceAll("/issues", "/issues<!-- -->").replaceAll("/pull", "/pull<!-- -->")
+        }\n\n`,
+        labels: ["🤖 Auto", "📝 Suggestion"]
+    })
+    await m.edit({
         embeds: [
             new EmojiEmbed()
-                .setTitle("Suggestion")
-                .setDescription(
-                    `**From:** ${renderUser(
-                        interaction.member!.user as Discord.User
-                    )}\n**Suggestion:**\n> ${suggestion}\n\n` +
-                        `**Server:** ${interaction.guild!.name} (${interaction.guild!.id})\n`
-                )
-                .setStatus("Warning")
+                .setEmoji("ICONS.ADD")
+                .setTitle(`Suggestion from ${interaction.user.tag} (${interaction.user.id})`)
+                .setDescription(`**Suggestion:**\n> ${suggestionDesc}\n\n`)
+                .setStatus("Success")
+                .setFooter({text: `${issue.data.number}`})
         ],
         components: [
-            new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents(
-                new Discord.ButtonBuilder()
-                    .setCustomId("suggestionAccept")
-                    .setLabel("Accept")
-                    .setStyle(ButtonStyle.Secondary)
-                    .setEmoji(getEmojiByName("ICONS.ADD", "id")),
-                new Discord.ButtonBuilder()
-                    .setCustomId("suggestionDeny")
-                    .setLabel("Delete")
-                    .setStyle(ButtonStyle.Secondary)
-                    .setEmoji(getEmojiByName("ICONS.REMOVE", "id"))
+            new Discord.ActionRowBuilder<ButtonBuilder>().addComponents(
+                new ButtonBuilder().setCustomId("accept:Suggestion").setLabel("Accept").setStyle(ButtonStyle.Success),
+                new ButtonBuilder().setCustomId("deny:Suggestion").setLabel("Deny").setStyle(ButtonStyle.Danger),
+                new ButtonBuilder().setCustomId("close:Suggestion").setLabel("Close").setStyle(ButtonStyle.Secondary),
+                new ButtonBuilder().setCustomId("implemented:Suggestion").setLabel("Implemented").setStyle(ButtonStyle.Secondary),
+                new ButtonBuilder().setLabel(`Open Issue #${issue.data.number}`).setStyle(ButtonStyle.Link).setURL(`https://github.com/ClicksMinutePer/Nucleus/issues/${issue.data.number}`),
+            ),
+            new Discord.ActionRowBuilder<ButtonBuilder>().addComponents(
+                new ButtonBuilder().setCustomId("lock:Suggestion").setLabel("Lock").setStyle(ButtonStyle.Danger),
+                new ButtonBuilder().setCustomId("spam:Suggestion").setLabel("Mark as Spam").setStyle(ButtonStyle.Danger),
             )
         ]
-    });
+    })
     await interaction.editReply({
         embeds: [
             new EmojiEmbed()
