import { Message } from "discord.js"; export const handleDeleteCommand = async (message: Message) => { if (message.author.bot) return; if (message.content.toLowerCase().startsWith("uma!delete")) { const application = await message.client.application?.fetch(); const ownerId = application?.owner?.id; if (message.author.id !== ownerId) { await message.reply("❌ Only the server owner can use this command."); return; } const parameters = message.content.split(" ").slice(1); if (parameters.length < 1) { await message.reply( "❌ Usage: `uma!delete `\nExample: `uma!delete 1234567890123456789`" ); return; } const messageId = parameters[0]; if (!/^\d{17,19}$/.test(messageId)) { await message.reply("❌ Invalid message ID format. Please provide a valid Discord message ID."); return; } try { let targetMessage = null; try { targetMessage = await message.channel.messages.fetch(messageId); } catch { if (message.guild) for (const channel of message.guild.channels.cache.values()) if (channel.isTextBased()) try { targetMessage = await channel.messages.fetch(messageId); if (targetMessage) break; } catch { continue; } } if (!targetMessage) { await message.reply("❌ Message not found. Make sure the message ID is correct and the message exists."); return; } await targetMessage.delete(); await message.delete(); } catch (error) { console.error("Error deleting message:", error); await message.reply("❌ Failed to delete the message. Check bot permissions and try again."); } } };