【发布时间】:2020-12-15 22:10:21
【问题描述】:
所以我正在开发一个不和谐的机器人,我想发出一个命令,当用户键入“.doggo”时,会出现一条狗的随机图像。这是我当前命令的代码。我已经在应用程序中安装了 node-fetch 和 discord.js 库。
else if(command === 'doggo') {
const Fetch = fetch('https://dog.ceo/api/breeds/image/random');
const embed = new Discord.MessageEmbed()
.setTitle('doggo :dog:')
.setImage(Fetch);
message.channel.send(embed);
}
由于某种原因,我在执行命令时收到此警告消息:
(node:10416) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
embed.image.url: Could not interpret "{}" as string.
at RequestHandler.execute (C:\Users\jnett\Desktop\demon\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:10416) 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:10416) [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.
我的代码有什么问题?我需要做什么来修复它?
【问题讨论】:
-
fetch()是异步的并返回一个承诺 -
那个 api 返回什么?
标签: javascript node.js node-fetch