diff --git a/src/commands/settings/logs/warnings.ts b/src/commands/settings/logs/warnings.ts
index 3855d34..6e5482c 100644
--- a/src/commands/settings/logs/warnings.ts
+++ b/src/commands/settings/logs/warnings.ts
@@ -1,8 +1,6 @@
 import { LoadingEmbed } from "../../../utils/defaults.js";
-import { ChannelType } from "discord-api-types/v9";
-import Discord, { CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle, ButtonComponent } from "discord.js";
+import Discord, { CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelSelectMenuBuilder } from "discord.js";
 import EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
-import confirmationMessage from "../../../utils/confirmationMessage.js";
 import getEmojiByName from "../../../utils/getEmojiByName.js";
 import type { SlashCommandSubcommandBuilder } from "discord.js";
 import client from "../../../utils/client.js";
@@ -11,182 +9,86 @@
     builder
         .setName("warnings")
         .setDescription("Settings for the staff notifications channel")
-        .addChannelOption((option) =>
-            option
-                .setName("channel")
-                .setDescription("The channel to set the staff notifications channel to")
-                .addChannelTypes(ChannelType.GuildText)
-                .setRequired(false)
-        );
 
 const callback = async (interaction: CommandInteraction): Promise<unknown> => {
     if (!interaction.guild) return;
-    const m = (await interaction.reply({
+    await interaction.reply({
         embeds: LoadingEmbed,
         ephemeral: true,
         fetchReply: true
-    })) as Discord.Message;
-    if (interaction.options.get("channel")?.channel) {
-        let channel;
-        try {
-            channel = interaction.options.get("channel")?.channel;
-        } catch {
-            return await interaction.editReply({
-                embeds: [
-                    new EmojiEmbed()
-                        .setEmoji("CHANNEL.TEXT.DELETE")
-                        .setTitle("Staff Notifications Channel")
-                        .setDescription("The channel you provided is not a valid channel")
-                        .setStatus("Danger")
-                ]
-            });
-        }
-        channel = channel as Discord.TextChannel;
-        if (channel.guild.id !== interaction.guild.id) {
-            return interaction.editReply({
-                embeds: [
-                    new EmojiEmbed()
-                        .setTitle("Staff Notifications Channel")
-                        .setDescription("You must choose a channel in this server")
-                        .setStatus("Danger")
-                        .setEmoji("CHANNEL.TEXT.DELETE")
-                ]
-            });
-        }
-        const confirmation = await new confirmationMessage(interaction)
-            .setEmoji("CHANNEL.TEXT.EDIT")
-            .setTitle("Staff Notifications Channel")
-            .setDescription(
-                "This will be the channel all notifications, updates, user reports etc. will be sent to.\n\n" +
-                    `Are you sure you want to set the staff notifications channel to <#${channel.id}>?`
-            )
-            .setColor("Warning")
-            .setFailedMessage("No changes were made", "Success", "CHANNEL.TEXT.CREATE")
-            .setInverted(true)
-            .send(true);
-        if (confirmation.cancelled) return;
-        if (confirmation.success) {
-            try {
-                await client.database.guilds.write(interaction.guild.id, {
-                    "logging.staff.channel": channel.id
-                });
-                const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger;
-                const data = {
-                    meta: {
-                        type: "staffChannelUpdate",
-                        displayName: "Staff Notifications Channel Updated",
-                        calculateType: "nucleusSettingsUpdated",
-                        color: NucleusColors.yellow,
-                        emoji: "CHANNEL.TEXT.EDIT",
-                        timestamp: new Date().getTime()
-                    },
-                    list: {
-                        memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
-                        changedBy: entry(interaction.user.id, renderUser(interaction.user)),
-                        channel: entry(channel.id, renderChannel(channel))
-                    },
-                    hidden: {
-                        guild: interaction.guild.id
-                    }
-                };
-                log(data);
-            } catch (e) {
-                return interaction.editReply({
-                    embeds: [
-                        new EmojiEmbed()
-                            .setTitle("Staff Notifications Channel")
-                            .setDescription("Something went wrong and the staff notifications channel could not be set")
-                            .setStatus("Danger")
-                            .setEmoji("CHANNEL.TEXT.DELETE")
-                    ],
-                    components: []
-                });
-            }
-        } else {
-            return interaction.editReply({
-                embeds: [
-                    new EmojiEmbed()
-                        .setTitle("Staff Notifications Channel")
-                        .setDescription("No changes were made")
-                        .setStatus("Success")
-                        .setEmoji("CHANNEL.TEXT.CREATE")
-                ],
-                components: []
-            });
-        }
-    }
-    let clicks = 0;
-    const data = await client.database.guilds.read(interaction.guild.id);
+    })
+
+    let data = await client.database.guilds.read(interaction.guild.id);
     let channel = data.logging.staff.channel;
-    let timedOut = false;
-    while (!timedOut) {
-        await interaction.editReply({
-            embeds: [
-                new EmojiEmbed()
-                    .setTitle("Staff Notifications channel")
-                    .setDescription(
-                        channel
-                            ? `Your staff notifications channel is currently set to <#${channel}>`
-                            : "This server does not have a staff notifications channel"
-                    )
-                    .setStatus("Success")
-                    .setEmoji("CHANNEL.TEXT.CREATE")
-            ],
-            components: [
-                new ActionRowBuilder<ButtonBuilder>().addComponents([
-                    new ButtonBuilder()
-                        .setCustomId("clear")
-                        .setLabel(clicks ? "Click again to confirm" : "Reset channel")
-                        .setEmoji(getEmojiByName(clicks ? "TICKETS.ISSUE" : "CONTROL.CROSS", "id"))
-                        .setStyle(ButtonStyle.Danger)
-                        .setDisabled(!channel)
-                ])
-            ]
-        });
-        let i;
-        try {
-            i = await m.awaitMessageComponent({
-                time: 300000,
-                filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id && i.message.id === m.id }
-            });
-        } catch (e) {
-            timedOut = true;
-            continue;
-        }
-        await i.deferUpdate();
-        if ((i.component as ButtonComponent).customId === "clear") {
-            clicks ++;
-            if (clicks === 2) {
-                clicks = 0;
-                await client.database.guilds.write(interaction.guild.id, null, ["logging.staff.channel"]);
-                channel = null;
-            }
-        }
-    }
-    await interaction.editReply({
-        embeds: [
-            new EmojiEmbed()
-                .setTitle("Staff Notifications channel")
-                .setDescription(
-                    channel
-                        ? `Your staff notifications channel is currently set to <#${channel}>`
-                        : "This server does not have a staff notifications channel"
-                )
-                .setStatus("Success")
-                .setEmoji("CHANNEL.TEXT.CREATE")
-                .setFooter({ text: "Message closed" })
-        ],
-        components: [
-            new ActionRowBuilder<ButtonBuilder>().addComponents([
+    let closed = false;
+    do {
+        const channelMenu = new ActionRowBuilder<ChannelSelectMenuBuilder>()
+        .addComponents(
+            new ChannelSelectMenuBuilder()
+                .setCustomId("channel")
+                .setPlaceholder("Select a channel")
+        );
+        const buttons = new ActionRowBuilder<ButtonBuilder>()
+            .addComponents(
                 new ButtonBuilder()
                     .setCustomId("clear")
                     .setLabel("Clear")
-                    .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
-                    .setStyle(ButtonStyle.Secondary)
-                    .setDisabled(true)
-            ])
-        ]
-    });
+                    .setStyle(ButtonStyle.Danger)
+                    .setEmoji(getEmojiByName("CONTROL.CROSS", "id") as Discord.APIMessageComponentEmoji)
+                    .setDisabled(!channel),
+                new ButtonBuilder()
+                    .setCustomId("save")
+                    .setLabel("Save")
+                    .setStyle(ButtonStyle.Success)
+                    .setEmoji(getEmojiByName("ICONS.SAVE", "id") as Discord.APIMessageComponentEmoji)
+                    .setDisabled(channel === data.logging.staff.channel)
+            );
+
+        const embed = new EmojiEmbed()
+            .setTitle("Staff Notifications Channel")
+            .setStatus("Success")
+            .setEmoji("CHANNEL.TEXT.CREATE")
+            .setDescription(
+                `Logs which require an action from a moderator or administrator will be sent to this channel.\n` +
+                `**Channel:** ${channel ? `<#${channel}>` : "*None*"}\n`
+            )
+
+        await interaction.editReply({
+            embeds: [embed],
+            components: [channelMenu, buttons]
+        });
+
+        let i: Discord.ButtonInteraction | Discord.SelectMenuInteraction;
+        try {
+            i = (await interaction.channel!.awaitMessageComponent({
+                filter: (i) => i.user.id === interaction.user.id,
+                time: 300000
+            })) as Discord.ButtonInteraction | Discord.SelectMenuInteraction;
+        } catch (e) {
+            closed = true;
+            break;
+        }
+        await i.deferUpdate();
+        if(i.isButton()) {
+            switch (i.customId) {
+                case "clear": {
+                    channel = null;
+                    break;
+                }
+                case "save": {
+                    await client.database.guilds.write(interaction.guild!.id, {
+                        "logging.warnings.channel": channel
+                    });
+                    data = await client.database.guilds.read(interaction.guild!.id);
+                    break;
+                }
+            }
+        } else {
+            channel = i.values[0]!;
+        }
+    } while (!closed);
+
+    await interaction.deleteReply()
 };
 
 const check = (interaction: CommandInteraction, _partial: boolean = false) => {
