Javascript data.json();当它每隔一位正常工作时,就会抛出一个错误

Javascript data.json();当它每隔一位正常工作时,就会抛出一个错误,javascript,node.js,json,discord.js,bots,Javascript,Node.js,Json,Discord.js,Bots,我正在使用node.js开发discord机器人。一切都很顺利,只有一件事。这应该是一个Hypix公会桥梁机器人,基本上我可以通过discord频道向Hypix公会聊天室发送消息,反之亦然。不要紧的是,我想添加一个带有slothpixel的统计检查器,但我在discord机器人命令(works)中使用的代码在mineflayer上似乎无法获取 代码如下: if(msg.toLowerCase().includes(“!bedwars”)){ 设p=msg.replace(“!bedwars”,”

我正在使用node.js开发discord机器人。一切都很顺利,只有一件事。这应该是一个Hypix公会桥梁机器人,基本上我可以通过discord频道向Hypix公会聊天室发送消息,反之亦然。不要紧的是,我想添加一个带有slothpixel的统计检查器,但我在discord机器人命令(works)中使用的代码在mineflayer上似乎无法获取

代码如下:

if(msg.toLowerCase().includes(“!bedwars”)){
设p=msg.replace(“!bedwars”,”);
让dataFetch=crossfetch(`https://api.slothpixel.me/api/players/${p}`);//。然后(dataFetch=>dataFetch.json()
让data=JSON.parse(dataFetch);
如果(data.error&&data.error==“播放器不存在”)
返回消息。回复('该播放器不存在');
让bw=data['stats']['BedWars'];
bot.chat(`/gc${p}的Bedwars星球:${bw.level}`);
}
以下是错误:

(node:35) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token o in JSON at position 1
    at JSON.parse (<anonymous>)
    at /home/container/mineflayer/message.js:67:22
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:35) 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:35) [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.
(node:35) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token o in JSON at position 1
    at JSON.parse (<anonymous>)
    at /home/container/mineflayer/message.js:67:22
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:35) 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: 2)

位置1处JSON中意外的标记o
您不应该尝试将非JSON的内容解析为JSON。换句话说,您的获取需要一些错误处理。如果响应不成功,则不应使用.json()或json。首先,应处理错误。其次,您尝试解析一个承诺
dataFetch
是一个承诺,您应该先等待它被解决。我该如何处理这个问题,api应该返回json,每次我在其他命令上使用它时它都会返回json,只是mineflayer one似乎没有