如何正确读取邮件中的url个附件?

How to properly read the url of attachments from messages?

我希望它在有人发送图像或发送 link 图像(如 Imgur)时读取,然后将附件 url 记录到频道。

我试过使用 if(message.attachments.length > 0 || message.content.includes(message.attachments)),但似乎完全没有用。我查看了 discord.js,它说 MessageAttachments 是一条消息中所有附件的集合,所以我试图解析它,然后让它将集合输出到一条消息中,但这似乎也没有做任何事情。没有错误或任何错误。

这是我在有人发送图片时的完整代码。

if(message.attachments.length > 0 || message.content.includes(message.attachments)){

 var promise1 = Promise.resolve(message.attachments);

 promise1.then(function(value) {
  client.channels.find("name","picture-log").send(value) 
 });

 //var att = new MessageAttachment();
 //client.channels.find("name","picture-log").send(`${message.author.tag} sent an embed of` + att.url) 
}

好吧message.attachments确实return图片或文件,但是只有直接上传到Discord的那些。
因此,如果你想过滤 URL,你需要使用 message.content,并使用正则表达式或类似的东西找到链接。
我试图为此制作一个正则表达式(可能不完美但应该有效):

function imgurLinks (message) {
  return message.match(/https?:\/\/(www.|i.|)imgur\.com[^\s]+/g);
}
var links = imgurLinks("hey take a look at this: https://i.imgur.com/ecSWPgA.png");
console.log(links);

那个函数 return 是一组 imgur 链接,从那里可以看到有多少链接(如果有的话),如果有就做一些事情。

client.channels.find("name","picture-log")
    .send(`${message.author.tag} sent imgur links: ${links.join(" ")}`)