简体   繁体   English

当尝试访问 hypixel api 中的“pricePerUnit”时,出现错误:TypeError: Cannot read property 'pricePerUnit' of undefined

[英]When trying to access the "pricePerUnit" in the hypixel api, i get the error: TypeError: Cannot read property 'pricePerUnit' of undefined

{"success":true,"lastUpdated":1598982272495,"products":{"BROWN_MUSHROOM":{"product_id":"BROWN_MUSHROOM","sell_summary":[{"amount":160,"pricePerUnit":13.9,"orders":1},{"amount":28503,"pricePerUnit":13.8,"orders":2},{"amount":71483,"pricePerUnit":13.4,"orders":3}, this is what the api says so i assumed that i could directly get the "pricePerUnit. But I am getting the error TypeError: Cannot read property 'pricePerUnit' of undefined {"success":true,"lastUpdated":1598982272495,"products":{"BROWN_MUSHROOM":{"product_id":"BROWN_MUSHROOM","sell_summary":[{"amount":160,"pricePerUnit":13.9,"orders":1},{"amount":28503,"pricePerUnit":13.8,"orders":2},{"amount":71483,"pricePerUnit":13.4,"orders":3},这是api 这样说,所以我假设我可以直接获得“pricePerUnit。但我收到错误类型错误TypeError: Cannot read property 'pricePerUnit' of undefined

My code is: ```client.on("message", message => { if (message.author.bot) return;我的代码是:```client.on("message", message => { if (message.author.bot) return;

const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();

if (command === "bazaar") {
    let product = args[0];

    fetch(`https://api.hypixel.net/skyblock/bazaar/product?key=${key}`)
    .then(result => result.json())
    .then(({ BROWN_MUSHROOM }) => {
        // Log the player's username
        message.reply(BROWN_MUSHROOM.pricePerUnit)
    })

}

})``` })```

anybody know how to help?有人知道怎么帮忙吗?

Try modifying your last block to this:尝试将您的最后一个块修改为:

.then(({ products: { BROWN_MUSHROOM } }) => {
    // Log the player's username
    message.reply(BROWN_MUSHROOM.pricePerUnit)
})

since BROWN_MUSHROOM appears to be under products field.因为BROWN_MUSHROOM似乎在products字段下。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:当我尝试访问 API 调用数据时,无法读取未定义的属性“映射” - TypeError: Cannot read property 'map' of undefined when I am trying to access API call data TypeError:无法读取未定义的属性“displayAvatarURL”:尝试 ping 另一个人以获取他们的头像时出现此错误 - TypeError: Cannot read property 'displayAvatarURL' of undefined: Get this error when trying to ping another person to get their avatar 我试图运行命令 Discord.js 但出现错误“TypeError:无法读取未定义的属性'get'” - i m trying to run a command Discord.js but error appear “TypeError: Cannot read property 'get' of undefined” 当我想访问对象详细信息时,React JS引发“ TypeError:无法读取未定义的属性'名称'”错误 - React JS throw “TypeError: Cannot read property 'name' of undefined” error when i want to access object details 类型错误:无法读取未定义的属性“then”。 当我尝试运行 updatefirst 函数时出现此错误 - TypeError: Cannot read property 'then' of undefined. Getting this error when I am trying to run updatefirst function 运行我的nodejs代码时收到此错误:'TypeError:无法读取未定义的属性'apply'。 ' - I get this error when running my nodejs code: ' TypeError: Cannot read property 'apply' of undefined. ' 将 elasticsearch 与 d3.js 集成时,“Uncaught TypeError: Cannot read property 'Client' of undefined” 我收到此错误 - When integrate elasticsearch with d3.js, “Uncaught TypeError: Cannot read property 'Client' of undefined” I get this error 提交空搜索请求时收到错误“TypeError:无法读取未定义的属性“地图” - I get the error 'TypeError: Cannot read property 'map' of undefined' when submitting a empty search request 使用 useEffect 调用 API。 当尝试映射用户时,它说 TypeError: Cannot read property 'map' of undefined - Calling an API With useEffect . when Trying to mapping user it is saying TypeError: Cannot read property 'map' of undefined Next.js 类型错误:尝试控制台记录 api 结果时无法读取未定义的属性“” - Next.js TypeError: Cannot read property '' of undefined when trying to console log api results
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM