Discord.js v14 健康图像错误 (Node.js)

Discord.js v14 Wholesome image erroring (Node.js)

提问人:Adelto isbest 提问时间:11/9/2023 更新时间:11/9/2023 访问量:22

问:

我一直在尝试为我的 discord 服务器制作一个 wholesomeimg cmd,但由于某种原因它无法正确获取 json。

我尝试了这段代码:

if (message.content === "m.sendwholesomeimg") {
      if (message.member.permissions.has(PermissionsBitField.Flags.ManageGuild) || message.author.id === "1015205495780413480") {
        const url = await fetch("https://www.reddit.com/r/aww/random/.json");
        const random = await url.json();
        await message.guild.channels.cache.find((channel) => channel.name.toLowerCase() === `🐇・wholesome`).send(`${random[0].data.children[0].data.url}`);
      } else {
      message.reply('You do not have permission to use this command.')
    } 
  }

但它出现了这个错误:

node:events:491
      throw er; // Unhandled 'error' event
      ^

SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at Response.json (/nix/store/qpnf0dafrfsbcwb4z7cphjm0dff0vl7l-prybar-nodejs-0.0.0-e0d9a52/prybar_assets/nodejs/node_modules/@replit/node-fetch/index-3a548b1a.js:635:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
    at emitUnhandledRejectionOrErr (node:events:394:10)

Node.js v18.12.1
javascript 节点 .js 不和谐 不和谐.js

评论

0赞 Tony I. 11/9/2023
看起来它获取了 HTML,可能是因为一些错误。你能不能在前面行,这样我们才能看到?console.log(url)const random =....

答: 暂无答案