Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 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
930f89b
[style,feat,meta]: prettier; update webhook typings and tsconfig
null8626 Feb 17, 2026
6cf58c1
feat: add trace property to webhook payload
null8626 Feb 17, 2026
55d920a
doc: fix typing documentation for WebhookTestPayload
null8626 Feb 17, 2026
6e29493
feat: make votedAt and expiresAt a Date type for consistency
null8626 Feb 17, 2026
19e319f
meta: update project metadata to make jest work
null8626 Feb 17, 2026
52968df
feat: add integration.create and integration.delete support
null8626 Feb 17, 2026
6635d9a
feat: more consistent naming
null8626 Feb 17, 2026
0c9b1b0
doc: update webhook documentation
null8626 Feb 18, 2026
c79e357
feat: remove deprecated webhook via middleware method
null8626 Feb 18, 2026
c8990db
fix: remove overridden 204 response in webhooks
null8626 Feb 18, 2026
8eb621b
feat: add two more missing properties to Vote
null8626 Feb 18, 2026
6e71450
feat: rename avatarURL to avatar for consistency
null8626 Feb 18, 2026
9975bcb
doc: add missing documentation for WebhookPayload
null8626 Feb 19, 2026
8dffd4c
feat: add getVotes
null8626 Feb 20, 2026
b6de1e5
fix: return 403 instead of 401 in case of invalid signature
null8626 Feb 20, 2026
8c791c6
doc: fix NameError in documentation examples
null8626 Feb 20, 2026
37e6f0e
doc: log payload directly
null8626 Feb 20, 2026
3c956d6
doc: use an, not a
null8626 Feb 24, 2026
497ae27
refactor: more accurate HTTP response status codes
null8626 Feb 25, 2026
a0e1ca7
doc: grammatical fixes
null8626 Feb 25, 2026
f1ad1cf
fix: add missing semicolons
null8626 Feb 25, 2026
fd27514
refactor: remove token validation
null8626 Mar 3, 2026
2128574
feat: rename created_at to voted_at
null8626 Mar 4, 2026
3d350bf
feat: rename userId to voterId for clarity
null8626 Mar 5, 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
212 changes: 177 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,204 @@
# 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)
- [Getting a cursor-based paginated list of votes for your project](#getting-a-cursor-based-paginated-list-of-votes-for-your-project)
- [Posting your bot's application commands list](#posting-your-bots-application-commands-list)
- [Generating widget URLs](#generating-widget-urls)
- [Webhooks](#webhooks)

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");
```

### Getting a cursor-based paginated list of votes for your project

```js
const firstPage = await client.getVotes(new Date("2026-01-01"));
console.log(firstPage.votes);

const secondPage = await firstPage.next();
console.log(secondPage.votes);
```

### Posting your bot's application commands list

#### Discord.js

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

[Documentation](https://topgg.js.org)
await client.postCommands(commands);
```

#### Eris

```js
const commands = await bot.getCommands();

await client.postCommands(commands);
```

#### Discordeno

```js
import { getApplicationCommands } from "discordeno";

const commands = await getApplicationCommands(bot);

await client.postCommands(commands);
```

[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)
#### Harmony

# Popular Examples
```js
const commands = await bot.interactions.commands.all();

## 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)
#### Oceanic

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

await client.postCommands(commands);
```

AutoPoster("topgg-token", client).on("posted", () => {
console.log("Posted stats to Top.gg!");
});
#### 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

#### Large

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

## Webhook server
#### Votes

```js
const express = require("express");
const Topgg = require("@top-gg/sdk");
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

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("/webhook", webhook.listener((payload) => {
console.log(payload);
}));

app.listen(8080);
```
6 changes: 4 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,12 +31,14 @@
"@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",
"express": "^4.18.2",
"husky": "^8.0.3",
"jest": "^29.6.4",
"jest-util": "^30.2.0",
"lint-staged": "^14.0.1",
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
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