Skip to content

JavaScript

TopStats SDK

Welcome to the community maintained Node.js client for the topstats.gg API.

  1. Install TopStats SDK

    Terminal window
    npm install @topstats/sdk
  2. Initialize the Client

    import { Client } from "@topstats/sdk";
    const client = new Client("YOUR_TOKEN");
  3. Make Your First Request

    // Get information about a bot
    const bot = await client.getBot("583807014896140293");
    console.log(bot.name, bot.server_count);

Usage Examples

// Get detailed bot information
const bot = await client.getBot("583807014896140293");
console.log(bot.name, bot.server_count);

API Reference

Methods

getBot(botId: string): Promise<BotData>
// Example
const bot = await client.getBot("583807014896140293");

Response Types

interface BotData {
id: string;
name: string;
server_count: number;
monthly_votes: number;
total_votes: number;
// ... and more
}

Error Handling

try {
await client.getBot("invalid-id");
} catch (error) {
if (error instanceof RateLimitError) {
console.log("Rate limited, try again later");
} else if (error instanceof TopStatsError) {
console.error("API Error:", error.message);
}
}

Rate Limits

The API implements rate limiting to ensure fair usage. For detailed information about rate limits and best practices, please refer to our rate limit documentation.