Skip to content
Advertisement

Unhandled Rejection: TypeError: Cannot read properties of undefined (reading ‘0’) getting error while trying to print JSON object in discord.js v14

I want to take the names from data.json and post it on a discord embed. For example I tried to print Animal Skull in a embed but it gave me that error.

error

JavaScript

test.js

JavaScript

my data.json

JavaScript

I would be really gratefull if anyone can help me.

Advertisement

Answer

You should use require to get data from json

JavaScript

And your json contains an array of objects so use datapath[0].names to get Animal skull

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement