@top-gg/sdk
TypeScript icon, indicating that this package has built-in type declarations

3.1.6 • Public • Published

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 at top.gg/bot/(BOT_ID)/webhooks and copying the token.

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

Popular Examples

Auto-Posting stats

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

const client = Discord.Client(); // Your discord.js client or any other
const { AutoPoster } = require("topgg-autoposter");

AutoPoster("topgg-token", client).on("posted", () => {
  console.log("Posted stats to Top.gg!");
});

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.listener((vote) => {
    // vote is your vote object
    console.log(vote.user); // 221221226561929217
  })
); // attach the middleware

app.listen(3000); // your port

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

/@top-gg/sdk/

    Package Sidebar

    Install

    npm i @top-gg/sdk

    Homepage

    topgg.js.org

    Weekly Downloads

    5,342

    Version

    3.1.6

    License

    Apache-2.0

    Unpacked Size

    43.7 kB

    Total Files

    21

    Last publish

    Collaborators

    • galkon
    • veld
    • jpbberry