javascript - 如何将图像保存到 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
解决方案
推荐阅读
- python - 简单使用“import as”加载多场景数据?
- ruby-on-rails - 为什么 Chrome 驱动程序崩溃或元素不在 Cron 作业中?
- php - 如何使用 guzzlehttp 客户端将身份验证类型设置为抢占式
- php - 添加 xml-stylesheet 标签 simpleXML php
- sql - 删除 SQL 行和所有依赖项
- django - 将选定的下拉值从 react js 发送到 django ORM
- php - 在每个循环中输出某个 $_SESSION 变量
- java - I can not retrieve the current custom user object from Spring Security Context
- c++ - 为什么 QDir::exists() 在 docker 容器中不起作用?
- javascript - 如何在 Jade 中动态构建 jsTree?