简体   繁体   English

UnhandledPromiseRejectionWarning:错误:ENOENT:没有这样的文件或目录,stat'/assets/level.png'

[英]UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, stat '/assets/level.png'

So currently, I'm working on a project within an application you may know - Discord. 因此,目前,我正在开发您可能知道的应用程序中的一个项目-Discord。 I am currently trying to code a bot and have come to the task of getting it to send images from a local file source. 我目前正在尝试编写一个机器人程序,并完成了使其从本地文件源发送图像的任务。 My bot is hosted with Heroku which means all the files are local to the cloud it is on and every file I upload is maintained in the hierarchy it is in when pushed. 我的机器人由Heroku托管,这意味着所有文件都位于其所在的云本地,并且我上载的每个文件都按推送时所在的层次结构进行维护。 Moreover, I have uploaded all the files I need and all the code is working and up-to-date apart from one little thing. 此外,除了一件小事,我已经上传了我需要的所有文件,并且所有代码都正在工作并且是最新的。 The file that I want to send. 我要发送的文件。

module.exports.run = async(bot, message, args) => {
    message.channel.send('', {files: ['../assets/level.png']});
};

These lines of code should send an image of a simple, grey rectangle (png) file. 这些代码行应发送一个简单的灰色矩形(png)文件的图像。 However.. it does not. 但是,事实并非如此。 Instead, my console returns these lines: 相反,我的控制台返回以下行:

2019-01-16T19:58:24.366174+00:00 app[worker.1]: (node:4) 
UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, stat '/assets/level.png'
2019-01-16T19:58:24.366478+00:00 app[worker.1]: (node:4) 
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated 
either by throwing inside of an async function without a catch block, or by rejecting a 
promise which was not handled with .catch(). (rejection id: 1)

Any suggestions on what the fix might be would be great. 关于此修复程序的任何建议都很好。 Also, if you would like to contact me on what my current files look like, please don't hesitate to contact me on Discord @ I'mALittleTeapot#0001. 此外,如果您想就我当前的文件格式与我联系,请随时与Discord @ I'mALittleTeapot#0001进行联系。 Thank you. 谢谢。

according to the docs of discord.js ( https://discord.js.org/#/docs/main/stable/class/DMChannel?scrollTo=send ) (checked the textchannel channel.send() & it looks the same) 根据discord.js的文档( https://discord.js.org/#/docs/main/stable/class/DMChannel?scrollTo=send )(检查了textchannel channel.send()并看起来相同)

this is how you call that function: 这是您调用该函数的方式:

// Send a local file
channel.send({
  files: [{
    attachment: 'entire/path/to/file.jpg',
    name: 'file.jpg'
  }]
})
  .then(console.log)
  .catch(console.error);

it looks like you need to provide a path for the attachment and a name for it (well the name is optional) 看起来您需要为附件提供一个路径并为其命名(该名称是可选的)

unsure of this but if channel.send does indeed support the syntax you used, then, I would look into that "entire/path/to/file.jpg" which strongly suggests you can't use relative paths . 不确定这一点,但是如果channel.send确实支持您使用的语法,那么, 我会研究“ entire / path / to / file.jpg”,它强烈建议您不能使用相对路径

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:ENOENT:没有这样的文件或目录,统计 - Error: ENOENT: no such file or directory, stat 错误:ENOENT:没有这样的文件或目录,stat ... .steampath - Error: ENOENT: no such file or directory, stat ... .steampath 错误:Enoent:没有这样的文件或目录,状态为'D:\\ awesome-testindex.html' - Error :Enoent :no such file or directory ,stat 'D:\awesome-testindex.html' 错误:ENOENT:没有这样的文件或目录,stat Laravel mix bug - Error: ENOENT: no such file or directory, stat Laravel mix bug 错误:ENOENT:没有这样的文件或目录,stat '/home/arpit/.steampath' - Error: ENOENT: no such file or directory, stat '/home/arpit/.steampath' 错误:ENOENT:没有这样的文件或目录 - Error: ENOENT: no such file or directory 当我导入 BrowserRouter 时,在 reactJS 中遇到此错误“错误:ENOENT:没有此类文件或目录,stat '/initrd.img'” - Encountering this error "Error: ENOENT: no such file or directory, stat '/initrd.img'" in reactJS when i import BrowserRouter 错误:ENOENT:没有这样的文件或目录,错误时统计“/public/main.html”(本机) - Error: ENOENT: no such file or directory, stat '/public/main.html' at Error (native) webpack + express + angular 4错误“错误:ENOENT:没有这样的文件或目录,统计信息'C:\\ public \\ index.html' - webpack + express + angular 4 error "Error: ENOENT: no such file or directory, stat 'C:\public\index.html' 服务器给出错误:ENOENT:没有这样的文件或目录,stat 'F:\\web development\\calculator\\index.html' - server is giving Error: ENOENT: no such file or directory, stat 'F:\web development\calculator \index.html '
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM