使用 discord bot 在聊天中读取文件

Reading files in chat using discord bot

作为实验,我试图找出是否可以读取作为附件输入到聊天中的文件,例如:图像文件、txt 等。

找了半天也没找到相关资料

所以可以使用 Discord.js 来做到这一点?如果是这样,我将如何去做?

这可以使用 attachments property of a Message to find the attachment and consequently its URL. You can then download the URL 来完成。它看起来像这样:

dClient.on('message', msg => {
    if (msg.attachments) {
        for (var key in msg.attachments) {
            let attachment = msg.attachments[key];
            download(attachment.url);
        }
    }
});