【发布时间】:2019-01-17 13:25:40
【问题描述】:
我最近遇到了一个问题,即用户在查看图片内容之前先拖钓然后删除图片。所以我正在创建一个日志以将所有内容下载到日志中。 (是的,我已经实例化了 fs.js)。但是由于某种原因,在写入文件时......文件只有 9 个字节大(并且内容只是“未定义”)。请帮忙。
var attachment = (message.attachments).array();
attachment.forEach(function(attachment) {
console.log(attachment.url);
tempName = attachment.url.split("/");
attachName = tempName[tempName.length-1]
console.log(attachName);
fs.writeFileSync(dir + "/" + attachName, attachment.file, (err) => {
// throws an error, you could also catch it here
if (err) throw err;
// success case, the file was saved
console.log('attachment saved!');
});
theLog += '<img src="'+ "attachments/" + message.channel.name + "/" + attachName + '"> \n';
//theLog += '<img src="'+ attachment.url + '"> \n';
})
【问题讨论】:
-
theLog到底是什么?您指的是它,但从不显示它的创建位置或写入文件的位置。请提供minimal reproducible example
标签: discord.js