簡體   English   中英

UnhandledPromiseRejectionWarning:錯誤:ENOENT:沒有這樣的文件或目錄,stat'/assets/level.png'

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

因此,目前,我正在開發您可能知道的應用程序中的一個項目-Discord。 我目前正在嘗試編寫一個機器人程序,並完成了使其從本地文件源發送圖像的任務。 我的機器人由Heroku托管,這意味着所有文件都位於其所在的雲本地,並且我上載的每個文件都按推送時所在的層次結構進行維護。 此外,除了一件小事,我已經上傳了我需要的所有文件,並且所有代碼都正在工作並且是最新的。 我要發送的文件。

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

這些代碼行應發送一個簡單的灰色矩形(png)文件的圖像。 但是,事實並非如此。 相反,我的控制台返回以下行:

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)

關於此修復程序的任何建議都很好。 此外,如果您想就我當前的文件格式與我聯系,請隨時與Discord @ I'mALittleTeapot#0001進行聯系。 謝謝。

根據discord.js的文檔( https://discord.js.org/#/docs/main/stable/class/DMChannel?scrollTo=send )(檢查了textchannel channel.send()並看起來相同)

這是您調用該函數的方式:

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

看起來您需要為附件提供一個路徑並為其命名(該名稱是可選的)

不確定這一點,但是如果channel.send確實支持您使用的語法,那么, 我會研究“ entire / path / to / file.jpg”,它強烈建議您不能使用相對路徑

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM