【发布时间】:2020-12-22 01:36:23
【问题描述】:
我正在使用 Discord.js 编写一个 Discord Bot,我正在让该机器人从一组中发送一个随机图像:
client.on('message', msg => {
if (msg.content === 'I Hate It'){
const randImg = ['https://i.imgur.com/C0gR27R.png', 'https://i.imgur.com/qErVhIm.jpg'];
msg.channel.send("", { files: randImg[Math.floor(Math.random() * randImg.length)]});
}
});
但是,当我运行代码并输入“我讨厌它”时,nodemon 给了我这个错误:
(node:13) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, stat '/home/container/h'
(node:13) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:13) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
根据错误,它正在尝试查找一个不存在的目录,但在代码中没有告诉它查找目录。我知道这是那个特定的块,因为所有其他命令和机器人的一部分都可以正常工作。我该如何解决这个问题?
【问题讨论】:
标签: javascript node.js discord discord.js