使用Discord Bot在聊天中读取文件 [英] Reading files in chat using discord bot

查看:362
本文介绍了使用Discord Bot在聊天中读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个实验,我试图确定我是否可以读取作为聊天附件输入的文件,例如:图像文件,txt等。

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.

那么,使用Discord.js可以做到这一点吗?如果是这样,我将如何去做呢?

So it possible to do this using Discord.js? If so, how would I go about doing it?

推荐答案

可以使用附件属性的消息以找到附件,因此其URL 。然后,您可以使用http和fs模块下载URL 。看起来像这样:

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

这篇关于使用Discord Bot在聊天中读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆