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

Asked Dec 28, 2023·3 replies·Last activity 2 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

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-cross… . 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-cross…",
{
method: "GET",
headers: {
"User-Agent": "Nightbot",
},
}
).then((res) => res.json());
}`

3 replies

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)