So, I made a command which registers pokémon you are shiny hunting for, how many you have got, and how many eggs it took/is taking for you to get the shiny, and it works fine. My problem is that some people forget the pokémon they did register in that storage, and so I would like to be able to send a message containing all the pokémon they registered in the Storage, like this:
You have registered the following pokémon: (All the pokémon you registered)
But, I don't know how to loop through the keys that are inside of the user's ID. Here's how my json file looks:
{ "User's ID": { "Pokémon": { "encounters": value, "shinies": value }, "Pokémon": { "encounters": value, "shinies": value } } }
I have tried looping like this:
const path = require('path'); const fs = require('fs'); const shiniesDataPath = path.resolve(__dirname, './Storage/shiniesData.json'); function loadShiniesData() { return JSON.parse(fs.readFileSync(shiniesDataPath).toString()); } const shiniesData = loadShiniesData(); var trainer = shiniesData[message.author.id]; if (args[0] === 'all') { for (var trainer in shiniesData) { message.channel.send([trainer]) } return; }
But it only loops through the ID's.
https://stackoverflow.com/questions/65401788/how-can-i-loop-through-a-non-determined-json-key-and-send-a-message-with-it December 22, 2020 at 08:30AM
没有评论:
发表评论