javascript - Discord bot 无法从计算机读取文件,即使它存在
问题描述
我正在我的不和谐机器人上创建一个命令,该命令下载图像,使用 python 对其进行修改,然后将图像作为消息返回。我一切正常,但似乎程序找不到我的文件?
这是代码的摘要版本:
async function downloadAndCreate(url,name,mode)
{
const response = await fetch(url);
const buffer = await response.buffer();
await fs.writeFile(`./commands/external/${name}`, buffer, () =>
console.log("Downloaded Image"));
// Downloads Image from discord url
var pythonApplication = spawn("python",["./commands/external/create.py",name,mode]);
pythonApplication.stdout.on('data', function(data) {
fileName = data.toString()
return fileName
});
// Opens python and returns edited file name. Python creates new image in same folder
}
fileName = await downloadAndCreate(messageInfo[0]["url"], image, mode);
setTimeout(function () {
message.channel.send({ files: [`Y:/WINDOWS/DiscordBot/commands/external/${fileName}`] })}, 2000);
// Timeout to make sure image is created before sending message
运行代码后,python 使用编辑后的图像创建一个新文件,但我也收到此错误并且没有返回消息:
(node:16472) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, stat 'Y:\WINDOWS\DiscordBot\commands\external\{insert image name}'
如果我导航到该路径,我可以看到图像存在并且应用了编辑。为什么 node js 无法读取这个文件,即使它存在于指定的文件夹中?
解决方案
推荐阅读
- javascript - 无法使用 Laravel (blade.php) 加载具有较长链接的样式
- visual-studio-2019 - 具有 ID #### 的进程未在 Visual Studio 2019 中运行
- .net-core - Bot Framework Composer开发的多语言bot中如何触发对应的QnAMaker
- spring-boot - 将数据从 Spring Boot 控制器传递到 Boostrap 模态
- powershell - 更改 Oulook 365 组日历权限
- ruby-on-rails - 将 S3 Bucket 文件夹内容转换为 Rails 应用程序中的列表
- scala - scala中Future(Int)和Future{Int}之间的区别
- css - 在 ckeditor 的 contents.css 中添加/更新版本号
- javascript - 将字符串数组转换为具有不同键JS的对象数组
- material-design - 我无法更新材料网络数据表中的数据