JavaScript
Links
Installation
npm install @top-gg/sdk
or yarn add @top-gg/sdk
If you're using deno, check out the unofficial deno 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 here: topgg-autoposter
npm i topgg-autoposter
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 on your bot through the dashboard before using this.
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)