Api

Top.gg API Client for Posting stats or Fetching data

Kind: global classLink: https://topggjs.rtfd.io <- Library docsLink: https://docs.top.gg <- API Reference

new Api(token, options)

Create Top.gg API instance

Param Type Description
token string Token or options
options object API Options

Example

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

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

api.postStats(stats) ⇒ BotStats

Post bot stats to Top.gg (Do not use if you supplied a client)

Kind: instance method of ApiReturns: BotStats - Passed object

Param Type Description
stats Object Stats object
stats.serverCount number Server count
stats.shardCount number Shard count
stats.shardId number Posting shard (useful for process sharding)

Example

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

api.getStats(id) ⇒ BotStats

Get a bots stats

Kind: instance method of ApiReturns: BotStats - Stats of bot requested

Param Type Description
id Snowflake Bot ID

Example

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

api.getBot(id) ⇒ BotInfo

Get bot info

Kind: instance method of ApiReturns: BotInfo - Info for bot

Param Type Description
id Snowflake Bot ID

Example

await client.getBot('461521980492087297') // returns bot info

api.getUser(id) ⇒ UserInfo

Get user info

Kind: instance method of ApiReturns: UserInfo - Info for user

Param Type Description
id Snowflake User ID

Example

await client.getUser('205680187394752512')
// =>
user.username // Xignotic

api.getBots(query) ⇒ BotsResponse

Get a list of bots

Kind: instance method of ApiReturns: BotsResponse - Return response

Param Type Description
query BotsQuery Bot Query

Example

// Finding by properties
await client.getBots({
  search: {
    username: 'shiro',
    certifiedBot: true
    ...any other bot object properties
  }
})
// =>
{
  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 client.getBots({
  fields: ['id', 'username']
})
// =>
{
  results: [
    {
      id: '461521980492087297',
      username: 'Shiro'
    },
    {
      id: '493716749342998541',
      username: 'Mimu'
    },
    ...
  ],
  ...
}

api.getVotes() ⇒ Array.<ShortUser>

Get users who’ve voted

Kind: instance method of ApiReturns: Array.<ShortUser> - Array of users who’ve votedExample

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

api.hasVoted(id) ⇒ Boolean

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

Kind: instance method of ApiReturns: Boolean - Whether the user has voted in the last 12 hours

Param Type Description
id Snowflake User ID

Example

await client.hasVoted('205680187394752512')
// => true/false

api.isWeekend() ⇒ Boolean

Whether or not the weekend multiplier is active

Kind: instance method of ApiReturns: Boolean - Whether the multiplier is activeExample

await client.isWeekend()
// => true/false