Get latest attachment from the channel

This commit is contained in:
loicbersier 2020-07-16 09:22:26 +02:00
parent 81a23658f9
commit 4f3270c9d5

11
utils/attachment.js Normal file
View file

@ -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];
});
};