Top.gg Documentation

/

Javascript

Official Top.gg Javascript library


Documentation

NPM Package

GitHub

Installation

npm install @top-gg/sdk or yarn add @top-gg/sdk

Posting bot stats

Posting your bot's statistics is a quick and easy way to show how many people use your bot. There's a simple library that uses our SDK to post statistics: topgg-autoposter

npm i topgg-autoposter

/index.js
const client = new Discord.Client() // Your discord.js or eris client (or djs ShardingManager)
const AutoPoster = require('topgg-autoposter')

const ap = AutoPoster('Your Top.gg Token', client)

ap.on('posted', () => {
  console.log('Posted stats to Top.gg!')
})

Webhooks

The API can also be configured to receive events for when users vote for your bot through webhooks via express. You must first configure webhooks in your bot through the dashboard before using this.

/index.js
const Topgg = require("@top-gg/sdk")
const express = require("express")

const app = express()

const webhook = new Topgg.Webhook("your webhook auth")

app.post("/dblwebhook", webhook.listener(vote => {
  // vote will be your vote object, e.g
  console.log(vote.user) // 395526710101278721 < user who voted\
  
  // You can also throw an error to the listener callback in order to resend the webhook after a few seconds
}))

app.listen(80)
Edit on GitHub