From 4f3270c9d5905c95fa31f7c2f8e2003e5eea52d5 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Thu, 16 Jul 2020 09:22:26 +0200 Subject: [PATCH] Get latest attachment from the channel --- utils/attachment.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 utils/attachment.js diff --git a/utils/attachment.js b/utils/attachment.js new file mode 100644 index 0000000..276c103 --- /dev/null +++ b/utils/attachment.js @@ -0,0 +1,11 @@ +// Take latest image in the channel +module.exports = function(message) { + return message.channel.messages.fetch().then(messages => { + // Could be better + return messages.map(m => { + let attachments = (m.attachments).array(); + if (attachments[0]) return attachments[0].url; + else return null; + }).filter(key => key != null)[0]; + }); +}; \ No newline at end of file