Trying to return a user's Rank from The Finals public leaderboard API

I want to be able to make a command that when called, returns the user’s rank on the leaderboard. The Finals leaderboard API is https://storage.googleapis.com/embark-discovery-leaderboard/leaderboard-crossplay-discovery-live.json . I gave nightbot this type of code to test querying the api but it returns “fetch is not defined” `main();

const FINALS_NAME = “rhexos#6890”;

async function main() {
const entries = await fetchLeaderboardEntries();
const entry = entries.find((e) => e.name == FINALS_NAME);

console.log({
name: entry.name,
rank: entry.r,
oneDayChange: entry.or - entry.r,
cashouts: entry.c,
fame: entry.f,
});
}

async function fetchLeaderboardEntries() {
return fetch(
https://storage.googleapis.com/embark-discovery-leaderboard/leaderboard-crossplay-discovery-live.json”,
{
method: “GET”,
headers: {
“User-Agent”: “Nightbot”,
},
}
).then((res) => res.json());
}`

not sure where u got this code from, but this is for integration into an app… console.log won’t do any good in a nightbot command, and the error is correct, “fetch” is not defined anywhere in there… i’m also not used to seeing a function called before it’s defined

it was just test code to ensure i could snag the details, it works when put in something like repl.it . i will try specifically defining fetch to see if that works and then i just need to figure what to replace console.log to in order for nightbot to output it.

can just put it at the end, or save it as a variable and call the variable at the end ^^ (whatever is last nightbot will put into chat)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.