Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
26a58c2
fix: fix GET /bots/votes not working
null8626 May 25, 2025
d2cb2ce
feat: add widgets
null8626 Jun 17, 2025
2327b15
feat: add small widgets
null8626 Jun 18, 2025
13982a5
style: remove trailing comma
null8626 Jun 23, 2025
46ef8d1
docs: readme overhaul
null8626 Jun 23, 2025
db99c59
feat: make webhooks more specific
null8626 Jun 24, 2025
327e15b
feat: remove features deprecated by v0
null8626 Jun 24, 2025
1a03b27
feat: remove BotStats
null8626 Jul 4, 2025
ed43118
deps: remove the dependence on @top-gg/eslint-config
null8626 Jul 16, 2025
b27d294
feat: adapt to v1
null8626 Sep 10, 2025
1b2027c
*: minor tweaks
null8626 Sep 12, 2025
157a44c
[doc,revert]: rename WebhookVotePayload to WebhookPayload, TopggAPIEr…
null8626 Sep 13, 2025
4192bd3
refactor: remove redundant checks
null8626 Sep 13, 2025
8f986e1
feat: separate v1 from v0
null8626 Sep 13, 2025
6d866f5
refactor: use Bearer prefix for legacy and new tokens
null8626 Sep 15, 2025
66adfe3
doc: add @see Webhook#voteListener
null8626 Sep 15, 2025
3a234ad
doc: update documentation and readme
null8626 Sep 15, 2025
b2652b2
meta: make SDK description clearer
null8626 Sep 15, 2025
89be620
revert: revert breaking changes to webhooks
null8626 Sep 16, 2025
6fe8cf4
revert: revert breaking changes
null8626 Sep 18, 2025
840abb8
doc: update readme
null8626 Oct 3, 2025
15fb73a
ci: bump github workflow dependency versions
null8626 Oct 7, 2025
1ddf708
doc: fix less accurate naming
null8626 Oct 10, 2025
59c5257
doc: objects, not dicts
null8626 Oct 10, 2025
aa408ac
doc: documentation tweaks
null8626 Oct 10, 2025
9f88be3
feat: rename postBotCommands to postCommands
null8626 Oct 10, 2025
eb64cb1
doc: readme tweak
null8626 Oct 10, 2025
2c159e0
doc: fix API version links in README.md
null8626 Oct 20, 2025
40cae1c
doc: remove for more information link from README
null8626 Oct 21, 2025
7d342ca
revert: revert changes to the GitHub Workflows and eslint rules
null8626 Feb 1, 2026
4572c80
revert: revert Authorization header change
null8626 Feb 1, 2026
6768ba1
revert: revert back to TopGGAPIError
null8626 Feb 1, 2026
3059297
revert: revert dependency version bumps
null8626 Feb 1, 2026
e1226fd
revert: revert script updates
null8626 Feb 1, 2026
0871797
fix: add discord-api-types to dev dependencies
null8626 Feb 1, 2026
5f70047
revert: revert changes to the error class
null8626 Feb 1, 2026
bc9011f
fix: remove unused import
null8626 Feb 1, 2026
ecd1dc1
doc: minor readme tweaks
null8626 Feb 1, 2026
2aef3eb
doc: fix mismatched jsdoc argument name
null8626 Feb 1, 2026
bb84644
feat: delete v0 APIs
null8626 Feb 2, 2026
7f4cd94
feat: add support for GET /v1/projects/@me
null8626 Feb 3, 2026
bb1a39e
style: fix eslint errors and warnings
null8626 Feb 3, 2026
cd651e2
feat: implement new webhook authorization approach
null8626 Feb 3, 2026
cd679c6
doc: add widgets example to readme
null8626 Feb 3, 2026
80e77e0
doc: add documentation for getSelf()
null8626 Feb 3, 2026
31712b6
refactor: use parsedSignature.t
null8626 Feb 3, 2026
0c1b82b
fix: forgot digest('hex')
null8626 Feb 3, 2026
12e2569
fix: add Bearer prefix to Authorization header
null8626 Feb 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint
npm run lint
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ logs/
*.log

!dist/
.eslintrc.json
eslint.config.js
.gitattributes
.gitignore
.github/
Expand Down
204 changes: 169 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,196 @@
# Top.gg Node SDK
# Top.gg Node.js SDK

An official module for interacting with the Top.<span>gg API
> For more information, see the documentation here: https://topgg.js.org.

# Installation
The community-maintained Node.js library for Top.gg.

`yarn add @top-gg/sdk` or `npm i @top-gg/sdk`
## Chapters

# Introduction
- [Installation](#installation)
- [Setting up](#setting-up)
- [Usage](#usage)
- [Getting your project's information](#getting-your-projects-information)
- [Getting your project's vote information of a user](#getting-your-projects-vote-information-of-a-user)
- [Posting your bot's application commands list](#posting-your-bots-application-commands-list)
- [Generating widget URLs](#generating-widget-urls)
- [Webhooks](#webhooks)
- [Being notified whenever someone voted for your project](#being-notified-whenever-someone-voted-for-your-project)

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.
## Installation

See [this tutorial](https://github.com/top-gg/rust-sdk/assets/60427892/d2df5bd3-bc48-464c-b878-a04121727bff) on how to retrieve your API token.

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

# Links
```sh
$ npm i @top-gg/sdk
```

### Yarn

```sh
$ yarn add @top-gg/sdk
```

## Setting up

```js
import Topgg from "@top-gg/sdk";

const client = new Topgg.Api(process.env.TOPGG_TOKEN);
```

## Usage

### Getting your project's information

```js
const project = await client.getSelf();

console.log(project);
// =>
// {
// id: '218109768489992192',
// name: 'Miki',
// type: 'bot',
// platform: 'discord',
// headline: 'A great bot with tons of features! language | admin | cards | fun | levels | roles | marriage | currency | custom commands!',
// tags: [
// 'anime',
// 'customizable-behavior',
// 'economy',
// 'fun',
// 'game',
// 'leveling',
// 'multifunctional',
// 'role-management',
// 'roleplay',
// 'social'
// ],
// votes: { current: 1120, total: 313389 },
// review: { score: 4.38, count: 62245 }
// }
```

### Getting your project's vote information of a user

#### Discord ID

```js
const vote = await client.getVote("661200758510977084");
```

#### Top.gg ID

```js
const vote = await client.getVote("8226924471638491136", "topgg");
```

### Posting your bot's application commands list

#### Discord.js

```js
const commands = (await bot.application.commands.fetch()).map(cmd => cmd.toJSON());

await client.postCommands(commands);
```

#### Eris

[Documentation](https://topgg.js.org)
```js
const commands = await bot.getCommands();

await client.postCommands(commands);
```

#### Discordeno

[API Reference](https://docs.top.gg) | [GitHub](https://github.com/top-gg/node-sdk) | [NPM](https://npmjs.com/package/@top-gg/sdk) | [Discord Server](https://discord.gg/EYHTgJX)
```js
import { getApplicationCommands } from "discordeno";

# Popular Examples
const commands = await getApplicationCommands(bot);

## Auto-Posting stats
await client.postCommands(commands);
```

If you're looking for an easy way to post your bot's stats (server count, shard count), check out [`topgg-autoposter`](https://npmjs.com/package/topgg-autoposter)
#### Harmony

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

await client.postCommands(commands);
```

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

```js
const commands = await bot.application.getGlobalCommands();

await client.postCommands(commands);
```

#### Raw

```js
await client.postCommands([
{
options: [],
name: 'test',
name_localizations: null,
description: 'command description',
description_localizations: null,
contexts: [],
default_permission: null,
default_member_permissions: null,
dm_permission: false,
integration_types: [],
nsfw: false
}
]);
```

With this your server count and shard count will be posted to Top.<span>gg
### Generating widget URLs

## Webhook server
#### Large

```js
const express = require("express");
const Topgg = require("@top-gg/sdk");
const widgetUrl = Topgg.Widget.large(Topgg.WidgetType.DiscordBot, "574652751745777665");
```

#### Votes

```js
const widgetUrl = Topgg.Widget.votes(Topgg.WidgetType.DiscordBot, "574652751745777665");
```

const app = express(); // Your express app
#### Owner

const webhook = new Topgg.Webhook("topggauth123"); // add your Top.gg webhook authorization (not bot token)
```js
const widgetUrl = Topgg.Widget.owner(Topgg.WidgetType.DiscordBot, "574652751745777665");
```

app.post(
"/dblwebhook",
webhook.listener((vote) => {
// vote is your vote object
console.log(vote.user); // 221221226561929217
})
); // attach the middleware
#### Social

app.listen(3000); // your port
```js
const widgetUrl = Topgg.Widget.social(Topgg.WidgetType.DiscordBot, "574652751745777665");
```

With this example, your webhook dashboard (`https://top.gg/bot/{your bot's id}/webhooks`) should look like this:
![](https://i.imgur.com/cZfZgK5.png)
### Webhooks

#### Being notified whenever someone voted for your project

With express:

```js
import { Webhook } from "@top-gg/sdk";
import express from "express";

const app = express();
const webhook = new Webhook(process.env.TOPGG_WEBHOOK_PASSWORD);

app.post("/votes", webhook.listener(vote => {
console.log(`A user with the ID of ${vote.user} has voted us on Top.gg!`);
}));

app.listen(8080);
```
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@top-gg/sdk",
"version": "3.1.6",
"description": "Official Top.gg Node SDK",
"version": "4.0.0",
"description": "A community-maintained Node.js API Client for the Top.gg API.",
"main": "./dist/index.js",
"scripts": {
"test": "jest --verbose",
Expand Down Expand Up @@ -31,6 +31,7 @@
"@types/node": "^20.5.9",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^6.6.0",
"discord-api-types": "^0.38.38",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-jest": "^27.2.3",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./structs/Api";
export * from "./structs/Webhook";
export * from "./structs/Widget";
export * from "./typings";
Loading