From dfe673bebcb310da99ff91a52be8b116c4e24560 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Thu, 8 Feb 2024 19:34:01 +0100 Subject: [PATCH] remove self roles slashcommand --- commands/admin/self_roles/slash.js | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/commands/admin/self_roles/slash.js b/commands/admin/self_roles/slash.js index 375b254..1326ff9 100644 --- a/commands/admin/self_roles/slash.js +++ b/commands/admin/self_roles/slash.js @@ -50,6 +50,44 @@ const registerSelfRoles = async (interaction) => { return response; }; +const removeSelfRoles = async (interaction, msgID) => { + const { channel } = interaction; + + try { + // Try fetching message from channel + await channel.messages.fetch(msgID); + } catch (error) { + console.error(error); + // Reply to acknowledge command + await interaction.reply({ + content: `Failed to fetch message!`, + ephemeral: true + }); + return; + } + + // Try deleting message from database + const count = await Message.destroy({ + where: { + id: msgID + } + }); + + // Set reply based on result of deletion + let response = 'Successfully removed'; + if (count === 0) + response = 'Failed to remove'; + + // Reply to acknowledge command + await interaction.reply({ + content: `${response} self roles from message!`, + ephemeral: true + }); + + console.info(`[INFO] Removed self roles from message with ID '${msgID}'.`); + +}; + export const data = new SlashCommandBuilder() .setName('self_roles') .setDMPermission(false) @@ -92,6 +130,17 @@ export const data = new SlashCommandBuilder() .addStringOption((option) => option.setName('emoji').setRequired(true).setDescription('The emoji to be reacted with.') ) + ) + .addSubcommand((subcommand) => + subcommand + .setName('remove') + .setDescription('Remove self roles from a message.') + .addStringOption((option) => + option + .setName('id') + .setRequired(true) + .setDescription('The ID to reference the message to be removed.') + ) ); export async function execute(interaction) { const { options } = interaction; @@ -120,6 +169,11 @@ export async function execute(interaction) { await addSelfRoles(interaction, msgID, role, emoji); break; } + case 'remove': { + const msgID = options.getString('id'); + await removeSelfRoles(interaction, msgID); + break; + } } if (createNew) {