A beautiful and elegant API wrapper for the dlist.gg API.
This wrapper is inspired by and built for the amazing dlist.gg platform - your place to find Discord Bots & Servers. We also acknowledge the excellent work done by Luna-devv/dlist.js which served as inspiration for this TypeScript-focused implementation.
npm install dlist-api-wrapper📦 Available on npm: https://www.npmjs.com/package/dlist-api-wrapper
To use the dlist-api-wrapper, you'll need an API key from the dlist.gg dashboard. You can get one by visiting https://discordlist.gg/bot/<your bot id>/dashboard/webhooks and clicking "Regenerate Token".
import { DListClient } from 'dlist-api-wrapper';
// Initialize the client with your bot's API key
const client = new DListClient('your-api-key-here');
// Now you can use the client to interact with the dlist.gg APIThe main client class for interacting with the dlist.gg API.
new DListClient(apiKey: string, options?: DListClientOptions)apiKey- Your bot's API key from the dlist.gg dashboardoptions- Optional configuration optionsbaseUrl- The base URL for the API (default:https://api.discordlist.gg/v0)timeout- The timeout for API requests in milliseconds (default:10000)
Methods for interacting with bot-related endpoints.
Updates a bot's guild count using the preferred PUT endpoint.
client.bot.setGuildCount(botId: string | number, count: number): Promise<boolean>botId- The ID of the botcount- The number of guilds the bot is in- Returns a promise that resolves to
trueif successful
Updates a bot's guild count using the POST endpoint variant. This is a compatibility endpoint, prefer setGuildCount() when possible.
client.bot.setGuildCountPost(botId: string | number, count: number): Promise<boolean>botId- The ID of the botcount- The number of guilds the bot is in- Returns a promise that resolves to
trueif successful
Updates a bot's guild count using the Top.gg compatible endpoint. This is a compatibility endpoint, prefer setGuildCount() when possible.
client.bot.setGuildCountTopGg(botId: string | number, count: number): Promise<boolean>botId- The ID of the botcount- The number of guilds the bot is in- Returns a promise that resolves to
trueif successful
Methods for handling webhook operations.
Verifies a webhook payload using JWT.
client.webhooks.verifyVote(secret: string, token: string): VoteDatasecret- The webhook secret used to sign the JWTtoken- The JWT token to verify- Returns the decoded vote data
- Throws a
WebhookVerificationErrorif verification fails
The library provides custom error classes for handling different types of errors:
DListError- Base error class for all dlist-api-wrapper errorsAuthenticationError- Thrown when API requests fail due to authentication issuesRateLimitError- Thrown when a request is rate limited by the APINotFoundError- Thrown when a resource is not foundBadRequestError- Thrown when the API returns a 400 Bad Request responseForbiddenError- Thrown when the API returns a 403 Forbidden responseServerError- Thrown when the API returns a 500 Internal Server Error responseWebhookVerificationError- Thrown when webhook verification fails
Example:
try {
await client.bot.setGuildCount('123456789012345678', 100);
} catch (error) {
if (error instanceof RateLimitError) {
console.error('Rate limited! Try again later.');
} else if (error instanceof AuthenticationError) {
console.error('Invalid API key!');
} else {
console.error('An error occurred:', error);
}
}import { DListClient } from 'dlist-api-wrapper';
const client = new DListClient('your-api-key-here');
async function updateGuildCount() {
try {
const botId = '123456789012345678';
const guildCount = 100;
const result = await client.bot.setGuildCount(botId, guildCount);
console.log('Guild count updated successfully:', result);
} catch (error) {
console.error('Failed to update guild count:', error);
}
}
updateGuildCount();import express from 'express';
import { DListClient, WebhookVerificationError } from 'dlist-api-wrapper';
// Initialize Express app
const app = express();
app.use(express.json());
// Initialize the client with your bot's API key
const client = new DListClient('your-api-key-here');
// Webhook secret from your dlist.gg dashboard
const webhookSecret = 'your-webhook-secret';
app.post('/webhook', (req, res) => {
try {
// The JWT token should be in the request body
const token = req.body;
// Verify the webhook data
const voteData = client.webhooks.verifyVote(webhookSecret, token);
console.log(`User ${voteData.userId} voted for bot ${voteData.botId}`);
// Reward the user for voting
return res.status(200).json({ success: true });
} catch (error) {
if (error instanceof WebhookVerificationError) {
return res.status(401).json({ error: 'Invalid webhook data' });
}
return res.status(500).json({ error: 'Internal server error' });
}
});
app.listen(3000, () => {
console.log('Server listening on port 3000');
});This library is written in TypeScript and provides full type definitions for all its features. You can import the types you need:
import { DListClient, VoteData, DListError } from 'dlist-api-wrapper';Available types:
DListClientOptions- Options for the DListClient constructorVoteData- Structure of the vote data received from webhooksCountPayload- Payload for updating a bot's guild countCompatCountPayload- Payload for updating a bot's guild count (compatibility format)DetailError- Error response from the APISetGuildCountResponse- Response from setting a bot's guild count