我想从data.json上取下names,并将其发布到一个不一致的嵌入上. 例如,我试图在嵌入中打印Animal Skull,但它给了我这个错误.
错误
Unhandled Rejection: TypeError: Cannot read properties of undefined (reading '0')
Test.js
const { EmbedBuilder } = require("discord.js");
const datapath = ('data.json')
module.exports = {
config: {
name: "test",
description: "Just a test command!",
},
permissions: ['SendMessages'],
owner: false,
run: async (client, message, args, prefix, config, db) => {
message.reply({ embeds: [
new EmbedBuilder()
.setDescription(datapath.names[0])
.setColor("Green")
] })
},
};
我的data.json
[
{
"names": "Animal Skull",
"itemtype": "Block, 32, 4, No, Yes",
"image": "https://static.wikia.nocookie.net/cubixworlds/images/4/4c/Animal_Skull.png/revision/latest?cb=20220720212850"
},
{
"names": "Asteroid Block",
"itemtype": "Block, 1, 1, No, Yes",
"image": "https://static.wikia.nocookie.net/cubixworlds/images/f/fe/Asteroid_Block.png/revision/latest?cb=20220725063800"
}
]
如果有人能帮我,我将不胜感激.