首页 > 解决方案 > 如何将图像保存到 discord.js 中的文件

问题描述

我正在尝试将图像上传到聊天并让不和谐机器人将图像保存在磁盘上

我仍然不太了解javascript,但这就是我所拥有的。我想在不使用外部库的情况下解决这个问题

message.attachments.forEach(a => {
   fs.writeFileSync(`./${a.name}`, a.file);
});
//this creates an undefined file

console.log(message.attachments.length);
//this prints undefined

const file = fs.createWriteStream("file.jpg");
const request = http.get(message.attachments[0].url, (response) => {
   response.pipe(file);
});
//this creates an empty file.jpg

标签: javascriptnode.jsfsdiscord.js

解决方案


推荐阅读