tekeke
tekeke

Reputation: 133

Discord.js getting data from a json file based on an var

This may be a stupid question but i'm trying to get data from a json file based on a variable but it just keeps returning undefined even if it already exists

const { e } = require('../../emojis.json')
var skin = "yellow";
let skin2 = client.emojis.cache.get(e.skin)

the json file (e) has the data stored like this

{
    "e": {
    "red": "808107222043328546",
    "blue": "821697709609320448",
    "green": "821698356526841856",
    "pink": "821700492244942888",
    "orange": "821700998799163392",
    "yellow": "821701148628353034",
    "black": "821701297274617856",
    "white": "821701424047849502",
    "purple": "821701518351663124",
    "brown": "821701610077552670",
    "cyan": "821701791354847232",
    "lime": "821701882011582464"
    }
}

its supposed to get the "yellow" id from the json file but doesn't work at all i don't want to use

client.emojis.cache.get(e.yellow)

because i would use the skin var to get a random color

Upvotes: 0

Views: 44

Answers (1)

blaumeise20
blaumeise20

Reputation: 2220

When using .skin, you tell JavaScript to return property skin of the object. If you want to have the property that is in skin, you have to use indexing:

let skin2 = client.emojis.cache.get(e[skin]);

This will give you the value of the property stored in skin.

Upvotes: 1

Related Questions