Reading files in chat using discord bot

冷暖自知 提交于 2020-01-16 08:04:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!