Class Api

Top.gg API Client for Posting stats or Fetching data

Example

const Topgg = require("@top-gg/sdk");

const api = new Topgg.Api("Your top.gg token");

Link

Library docs

Link

API Reference

Hierarchy

  • EventEmitter
    • Api

Constructors

  • Create Top.gg API instance

    Parameters

    • token: string

      Token or options

    • Optional options: APIOptions = {}

      API Options

    Returns Api

Methods

  • Get bot info

    Parameters

    • id: string

      Bot ID

    Returns Promise<BotInfo>

    Info for bot

    Example

    await api.getBot("461521980492087297"); // returns bot info
    
  • Get a list of bots

    Parameters

    Returns Promise<BotsResponse>

    Return response

    Example

    // Finding by properties
    await api.getBots({
    search: {
    username: "shiro",
    certifiedBot: true,
    },
    });
    // =>
    {
    results: [
    {
    id: '461521980492087297',
    username: 'Shiro',
    discriminator: '8764',
    lib: 'discord.js',
    ...rest of bot object
    }
    ...other shiro knockoffs B)
    ],
    limit: 10,
    offset: 0,
    count: 1,
    total: 1
    }
    // Restricting fields
    await api.getBots({
    fields: ["id", "username"],
    });
    // =>
    {
    results: [
    {
    id: '461521980492087297',
    username: 'Shiro'
    },
    {
    id: '493716749342998541',
    username: 'Mimu'
    },
    ...
    ],
    ...
    }
  • Get a bots stats

    Parameters

    • id: string

      Bot ID

    Returns Promise<BotStats>

    Stats of bot requested

    Example

    await api.getStats("461521980492087297");
    // =>
    {
    serverCount: 28199,
    shardCount 1,
    shards: []
    }
  • Get user info

    Parameters

    • id: string

      User ID

    Returns Promise<UserInfo>

    Info for user

    Example

    await api.getUser("205680187394752512");
    // =>
    user.username; // Xignotic
  • Get users who've voted

    Returns Promise<ShortUser[]>

    Array of users who've voted

    Example

    await api.getVotes();
    // =>
    [
    {
    username: 'Xignotic',
    id: '205680187394752512',
    avatar: '3b9335670c7213b3a2d4e990081900c7'
    },
    {
    username: 'iara',
    id: '395526710101278721',
    avatar: '3d1477390b8d7c3cec717ac5c778f5f4'
    }
    ...more
    ]
  • Get whether or not a user has voted in the last 12 hours

    Parameters

    • id: string

      User ID

    Returns Promise<boolean>

    Whether the user has voted in the last 12 hours

    Example

    await api.hasVoted("205680187394752512");
    // => true/false
  • Whether or not the weekend multiplier is active

    Returns Promise<boolean>

    Whether the multiplier is active

    Example

    await api.isWeekend();
    // => true/false
  • Post bot stats to Top.gg

    Parameters

    Returns Promise<BotStats>

    Passed object

    Example

    await api.postStats({
    serverCount: 28199,
    shardCount: 1,
    });

Generated using TypeDoc