Arrays TypeError:json.find不是函数(discord.js)

Arrays TypeError:json.find不是函数(discord.js),arrays,json,find,discord.js,Arrays,Json,Find,Discord.js,我试图用“json.find”来解决显示商品和价格的问题 例如 键入.shop basic kibble bot回复Name:Basic Kibble cost:k50 或键入。购买食品 机器人回复名称:食品成本k10 在bot.js中 bot.on(“消息”({作者、频道、内容})=>{ if(author.bot | | |!content.startsWith(prefix))返回; const args=content.slice(前缀.length).split(“”); const命

我试图用“json.find”来解决显示商品和价格的问题 例如 键入
.shop basic kibble

bot回复
Name:Basic Kibble cost:k50

或键入
。购买食品
机器人回复
名称:食品成本k10

在bot.js中

bot.on(“消息”({作者、频道、内容})=>{
if(author.bot | | |!content.startsWith(prefix))返回;
const args=content.slice(前缀.length).split(“”);
const命令=args.shift();
如果(命令==“车间”){
if(!args.length)返回message.channel.send(“您必须指定一项!”);
常量输入=args.join(“”);
const items=json.find((object)=>object.name===`item`);
如果(!items)返回channel.send(`${input}不是有效项!`);
send(`Name:${items.Name}成本:k${items.Cost}`);
}
});

您在评论中说了以下几点: “在shop.json文件
{”item:[{”name:“Basic Kibble”,“cost:50},{”name:“food”,“cost:10}]}

如果json是这样,则表示它是一个对象。您需要使用:

const items=json.item.find(object=>object.name===`item`)

在shop.json文件``{“item”:[{“name”:“Basic Kibble”,“cost”:50},{“name”:“food”,“cost”:10}]}``您是否需要或导入json文件?您在哪里定义“json”const json=require(./data/shop.json”);在bot.jstry
json.json().find()的顶部