erwin1234777 / node-sdk

An official module for interacting with the top.gg API

Home Page:https://top.gg/api/docs#jslib

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Top.gg Node SDK

An official module for interacting with the Top.gg API

Installation

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

Introduction

The base client is Topgg.Api, and it takes your top.gg token and provides you with plenty of methods to interact with the API.

Your Top.gg token can be found here

You can also setup webhooks via Topgg.Webhook, look down below at the examples for how to do so!

Links

Documentation

API Reference | GitHub | NPM | Discord Server

Auto-Posting

If you're looking for an easy way to post your bot's stats (server count, shard count), check out topgg-autoposter

Popular Examples

Auto-Posting stats

If you choose not to use topgg-autoposter you can always do it yourself manually;

const client = Discord.Client() // Your discord.js client

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

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

setInterval(() => {
  api.postStats({
    serverCount: client.guilds.cache.size,
    shardId: client.shard.ids[0], // if you're sharding
    shardCount: client.options.shardCount
  })
}, 1800000) // post every 30 minutes

With this your server count and shard count will be posted to top.gg

Webhook server

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

const app = express() // Your express app

const webhook = new Topgg.Webhook('topggauth123') // add your top.gg webhook authorization (not bot token)

app.post('/dblwebhook', webhook.middleware(), (req, res) => {
  // req.vote is your vote object e.g
  console.log(req.vote.user) // 221221226561929217
}) // attach the middleware

app.listen(3000) // your port

With this example, your webhook dashboard should look like this:

About

An official module for interacting with the top.gg API

https://top.gg/api/docs#jslib


Languages

Language:TypeScript 100.0%