danielwerg / r6api.js

🍫 Node.js wrapper around Rainbow Six Siege APIs
https://npm.im/r6api.js
MIT License
111 stars 19 forks source link

Unable to get the regions informations from getRanks #84

Closed adrien-gllmt closed 2 years ago

adrien-gllmt commented 2 years ago

Hey ! So im now trying for hours to get the seasonal KD out of getRanks, but this always return this : Capture d’écran (760) and always return that regions is undefined.

Did i miss something ? Or mby some parts are not working anymore ?

danielwerg commented 2 years ago

How come? Even in your screenshot it's not undefined. Need to see a code which returns undefined to be sure, but it looks like a problem on your side.

adrien-gllmt commented 2 years ago

Here it is : Capture d’écran (766) And here is the code im running with. I tried several things but it always fails at the same point, this code was my last attempt :


const { 0: rank} = await r6api.getRanks(platform, player.id, {regionIds: 'emea', boardIds: 'pvp_ranked' })
const { seasons: { "-1": { regions: { emea: { boards: { pvp_ranked }} } } } } = rank;
console.log(rank);
----------------------------------
//.addFields comes from discordjs lib
.addFields(
        { name: 'K/D', value: `${/* kd will be displayed here */}`, inline: true },
)
danielwerg commented 2 years ago

Not a package related issue.


There will never be season with array index of -1, change it to:

const { 0: rank } = await r6api.getRanks(
  platform, id, { regionIds: 'emea', boardIds: 'pvp_ranked' }
);
if (!rank) return;
const { seasons: { 25: { regions: { emea: { boards: { pvp_ranked }} } } } } = rank;
console.log(pvp_ranked);

Or even better to:

const rank = await r6api.getRanks(
  platform, id, { regionIds: 'emea', boardIds: 'pvp_ranked' }
).catch(console.error);
if (!rank || !rank.length) return; // handle error
const latestSeason = Object.values(rank[0]?.seasons || {}).slice(-1)[0];
if (!latestSeason) return; // handle error
const { regions: { emea: { boards: { pvp_ranked } } } } = latestSeason;
console.log(pvp_ranked);