Heroku FetchError: invalid json response body at https://some-random-api.ml/meme reason: Unexpected token < in JSON at position 0

Heroku FetchError: invalid json response body at https://some-random-api.ml/meme reason: Unexpected token < in JSON at position 0

我试图在 Heroku 上为我的 Discord 机器人 运行 添加一个生成随机模因的功能,但每次我尝试 运行 它时,它只会给我这个错误:FetchError: invalid json response body at https://some-random-api.ml/meme reason: Unexpected token < in JSON at position 0.我想知道 Heroku 是否有类似于 this 的东西?如果没有,是不是我的代码有问题(贴在下面):

const memes = require("random-memes");
const { randomHexColor } = require('../admin/colorgen.js');


module.exports = {
    name: 'meme',
    description: 'Never mind what the description is!',
    async execute(message, args, Discord, Client, bot) {
        memes.random().then(meme => {
            
            const newEmbed = new Discord.MessageEmbed()
            .setColor(randomHexColor())
            .setTitle(meme.caption)
            // .setURL(meme.image)
            .setDescription(`category: ${meme.category}`)
            .setImage(meme.image);
            
            message.channel.send({ embeds: [newEmbed] });
        })
    }
}

API可能是当时刚挂掉,我之前也运行进过同样的错误。尝试在 .then(... => { ... }) 之后使用 .catch 来处理错误并可能进行调试。

memes.random().then(meme => {
    console.log(meme)
}).catch(err => {
    console.log(err)
});

如果 NPM 包仍然出现错误,请尝试发送 node-fetch request to https://some-random-api.ml/meme which is the API that random-memes uses (source code).

const fetch = require('node-fetch');

const response = await fetch('https://some-random-api.ml/meme');
const data = await response.json();

console.log(data);

数据应该return类似于

{
  "id": number,
  "image": string,
  "caption": string,
  "category": string
}

然后你可以从那里开始。