问题
As an experiment, I was trying to find whether I could read files that were entered as attachments into chat eg: image files, txt, etc.
I've been looking around for a long while and I have still found no information on it.
So it possible to do this using Discord.js? If so, how would I go about doing it?
回答1:
This can be done using the attachments property of a Message to find the attachment and consequently its URL. You can then download the URL using the http and fs modules. It would look something like this:
dClient.on('message', msg => {
if (msg.attachments) {
for (var key in msg.attachments) {
let attachment = msg.attachments[key];
download(attachment.url);
}
}
});
来源:https://stackoverflow.com/questions/50435819/reading-files-in-chat-using-discord-bot