From 27a68073403460386c316a0ff0c349c3b3023bc4 Mon Sep 17 00:00:00 2001 From: neru Date: Fri, 6 Feb 2026 14:12:22 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20actually=20add=20mimic=20=F0=9F=98=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/bot/mimic.ts | 89 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/src/commands/bot/mimic.ts b/src/commands/bot/mimic.ts index e69de29..2dbfa5d 100644 --- a/src/commands/bot/mimic.ts +++ b/src/commands/bot/mimic.ts @@ -0,0 +1,89 @@ +import { ChatInputCommandInteraction, MessageCreateOptions, MessageFlags, SlashCommandBuilder, TextChannel } from "discord.js"; +import { Command } from "../../commands"; + +const builder = new SlashCommandBuilder() + .setName('bot-mimic') + .setDescription('Makes the bot send a message') + .addStringOption(opt => + opt + .setName('content') + .setDescription('The text content of the message') + .setRequired(false) + ) + .addAttachmentOption(opt => + opt + .setName('attachment') + .setDescription('An attachment for the message') + .setRequired(false) + ) + .addStringOption(opt => + opt + .setName('reply') + .setDescription('The message ID that the bot should reply to') + .setRequired(false) + ); + + +const command: Command = { + name: 'bot-mimic', + builder: builder, + ownerOnly: true, + execute: async (interaction: ChatInputCommandInteraction): Promise => { + await interaction.deferReply({ flags: MessageFlags.Ephemeral }); + + if (!interaction.channel?.isTextBased()) { + await interaction.editReply('This command can only be used in a text channel.'); + return; + } + + if (!interaction.channel.isSendable()) { + await interaction.editReply('Channel is not sendable'); + return; + } + + const content = interaction.options.getString('content'); + const attachment = interaction.options.getAttachment('attachment'); + const replyId = interaction.options.getString('reply'); + + if (!content && !attachment) { + await interaction.editReply('Unable to send empty message. Specify content or attachment, or both.'); + return; + } + + const channel = interaction.channel as TextChannel; + const message: MessageCreateOptions = {}; + + if (content) { + message.content = content; + } + + if (replyId) { + try { + const replyMessage = await channel.messages.fetch(replyId); + message.reply = { + messageReference: replyMessage.id + }; + } catch { + await interaction.editReply('Invalid message ID for reply.'); + return; + } + } + + if (attachment) { + message.files = [{ + attachment: attachment.proxyURL, + name: attachment.name + }]; + } + + try { + await channel.send(message); + await interaction.editReply('Message sent successfully.'); + } catch (error) { + console.error('Failed to send message:', error); + await interaction.editReply('Failed to send message.'); + } + } +} + +export default command;