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

    Example

    await api.getBot("461521980492087297"); // returns bot info
    

    Returns

    Info for bot

    Parameters

    • id: string

      Bot ID

    Returns Promise<BotInfo>

  • Get a list of bots

    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'
    },
    ...
    ],
    ...
    }

    Returns

    Return response

    Parameters

    Returns Promise<BotsResponse>

  • Get a bots stats

    Example

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

    Returns

    Stats of bot requested

    Parameters

    • id: string

      Bot ID

    Returns Promise<BotStats>

  • Get user info

    Example

    await api.getUser("205680187394752512");
    // =>
    user.username; // Xignotic

    Returns

    Info for user

    Parameters

    • id: string

      User ID

    Returns Promise<UserInfo>

  • Get users who've voted

    Example

    await api.getVotes();
    // =>
    [
    {
    username: 'Xignotic',
    discriminator: '0001',
    id: '205680187394752512',
    avatar: '3b9335670c7213b3a2d4e990081900c7'
    },
    {
    username: 'iara',
    discriminator: '0001',
    id: '395526710101278721',
    avatar: '3d1477390b8d7c3cec717ac5c778f5f4'
    }
    ...more
    ]

    Returns

    Array of users who've voted

    Returns Promise<ShortUser[]>

  • Get whether or not a user has voted in the last 12 hours

    Example

    await api.hasVoted("205680187394752512");
    // => true/false

    Returns

    Whether the user has voted in the last 12 hours

    Parameters

    • id: string

      User ID

    Returns Promise<boolean>

  • Whether or not the weekend multiplier is active

    Example

    await api.isWeekend();
    // => true/false

    Returns

    Whether the multiplier is active

    Returns Promise<boolean>

  • Post bot stats to Top.gg

    Example

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

    Returns

    Passed object

    Parameters

    Returns Promise<BotStats>

Generated using TypeDoc