code
if (interaction.commandName === 'comp-scrambles') {
let datascrams = {};
fs.readFile('scrambles.json', 'utf8', function(err, rawData){
let datascrams = rawData;
})
const replyscrams = datascrams[interaction.options.getString('cube')]['scrams'];
interaction.reply(replyscrams);
}
JSON:
{
"3x3": [
{
"scrams": "das"
}
]
}
I expect it to go to my JSON file and go in the cube depth, and then the scrambles and take that. But it says
C:UsersLogan AltOneDriveDesktopKinchServer Comp Botsrcindex.js:479
const replyscrams = datascrams[interaction.options.getString('cube')]['scrams'];
^
TypeError: Cannot read properties of undefined (reading 'scrams')
at Client.<anonymous> (C:UsersLogan AltOneDriveDesktopKinchServer Comp
``` which is the error message
2
Answers
The json you used as an example has "scrams" inside an array,
that would make your variable be:
added
[0]
, or any index you need, afterdatascrams[interaction.options.getString('cube')]
and before['scrams']
You could improve your code this way:
Code