From 6f8dd7ebf6d1b22a301bd62d611c71cbb4919b40 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Sat, 12 Apr 2025 03:20:18 +0200 Subject: [PATCH] tdoss: Pull the latest image in chat if none are provided limited to 20 last messages for now --- commands/misc/tdoss.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/commands/misc/tdoss.js b/commands/misc/tdoss.js index cc778bb..2c44fa5 100644 --- a/commands/misc/tdoss.js +++ b/commands/misc/tdoss.js @@ -32,9 +32,15 @@ module.exports = { } } else { - message.channel.send("You have to provide an image to use this command.\nEither through an attachment, a link, or you can reply to a message with an image attachment.") - fs.rmSync(`${directory}`, {recursive: true}) - return + let lastMessages = await message.channel.messages.fetch({limit: 20, cache: false}); + let lastMessageWithAttachment = lastMessages.find(m => m.attachments.size > 0); + if(!lastMessageWithAttachment){ + message.channel.send("Couldn't find an image to use this command on.") + fs.rmSync(`${directory}`, {recursive: true}) + return + } + url = lastMessageWithAttachment.attachments.first().url; + } // TODO: Download with correct extension. message.channel.sendTyping();