[英]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.