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.middleware(), (req, res) => {
  // req.vote wil lbe your vote object, e.g
  console.log(req.vote.user); // 395526710101278721 < user who voted
});

app.listen(80);
Edit on GitHub