【发布时间】:2020-08-29 05:10:31
【问题描述】:
我正在使用 discord.js 和 node.js 制作一个 Discord 机器人。我正在尝试制作两个命令,一个purr 命令和一个woof 命令。我正在使用node-fetch 从网络上获取图像并将它们发布到不和谐。这是我的代码:
else if (command === 'purr') {
const fetch = require('node-fetch');
fetch('https://aws.random.cat/meow').then(response => response.json());
const { file } = await fetch('https://aws.random.cat/meow').then(response => response.json());
const catEmbed = new Discord.MessageEmbed()
.setColor('#fbfb76')
.setTitle('Purr...')
.setImage(file)
.setFooter('Over 1000 free cat pics thanks to aws.random.cat :)');
message.channel.send(catEmbed);
}
else if (command === 'woof') {
const fetch = require('node-fetch');
fetch('https://dog.ceo/api/breeds/image/random').then(response => response.json());
const { file } = await fetch('https://dog.ceo/api/breeds/image/random').then(response => response.json());
message.channel.send(file);
}
purr 命令有效。 woof 命令……嗯,不是真的。它输出此错误:
DiscordAPIError: Cannot send an empty message
表示无法从dog.ceo/api/breeds/image/random 获取。由于它适用于purr 命令,但不适用于woof 命令,有人可以告诉我问题并建议如何解决吗?谢谢。
【问题讨论】:
-
我无法重现这个 rn,但我想说你需要像
send({ file })一样发送它,而不仅仅是在它需要一个字符串时发送它 -
唯一的问题是它输出的错误与我得到的相同
标签: node.js fetch bots discord.js