使用 discord bot 在聊天中读取文件 [英] Reading files in chat using 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.
我找了很久,还是没找到相关信息.
I've been looking around for a long while and I have still found no information on it.
那么使用 Discord.js 可以做到这一点吗?如果是这样,我将如何去做?
So it possible to do this using Discord.js? If so, how would I go about doing it?
推荐答案
这可以使用 attachments 属性noreferrer">消息 找到附件因此 它的 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屋!