2.0.3 • Published 5 months ago

dbl-sdk v2.0.3

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

DBL-SDK

Install

npm install dbl-sdk

Includes

  • automatic statistics poster (top.gg, Discordbotlist)
  • automatic vote counter (top.gg, Discordbotlist)

Setup

Setup is extremely simple

// Import your normal discord package.
import { Client, GatewayIntentBits } from 'discord.js';

// Import the DBL-SDK package.
import DBL from 'dbl-sdk';

// Create a client instance.
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

// Login (this **must** be done before creating a connection to the discord bot lists).
client.login('token').then((client) => {
    // Create a new DBL instance.
    new DBL(client, {
        topgg: {
            token: 'token',
        },
        dbl: {
            token: 'token',
        },
    });
});

// The tokens provided in the options of the DBL instance are not the bot token, but the token provided from the respective bot list.

Properties

@since 1.1.0

As of v1.1.0 you can get the cache stats in between updates with the client.stats property.

console.log(client.stats)

/* Output varies on the things you pass, these are all options when fully configured */

// Output

{
  createdAt: number, // The timestamp of the first post in this process
  updatedAt: number, // The timestamp of the most recent update in this process
  upvoteCount: number, // All votes combined between all hosts
  dbl: { upvotes: number, votes: Array<Record<string, string|number>> }, // The Discordbotlists data
  'top.gg': { upvotes: number, votes: Array<Record<string, string|number>> }, // The top.gg data
  shardId: number, // The id of the current shard
  shardCount: number, // The total count of shards
  guildCount: number, // The total number of guilds
  userCount: number // The total number of users
}

Events (config.emits = true)

There is 3 events that can be emitted as of now.

webhookCreate

@since 1.1.0
@deprecated

This event is deprecated and should be replaced with webhookInit.

client.on('webhookCreate', (client, stats, response, host) => {
    /* Emitted whenever stats are updated */

    client: typeof Discord.Client; // The client after the update
    stats: Record<string, number>; // The stats used to update
    response: Record<string, string | number>; // The direct response from the host
    host: 'top.gg' | 'dbl'; // The host that was updated
});

webhookInit

@since 1.2.0

client.on('webhookInit', (client, stats) => {
    /* Emitted whenever the first webhook update happens */

    client: typeof Discord.Client; // The client after the update
    stats: Record<string, number>; // The stats used to update
    response: Record<string, string | number>; // The direct response from the host
    host: 'top.gg' | 'dbl'; // The host that was updated
});

webhookError

@since 1.0.0

client.on('webhookError', (client, stats, error, host) => {
    /* Emitted whenever a post request returns an error */

    client: typeof Discord.Client; // The client after the error
    stats: Record<string, number>; // The stats used to try to update
    error: Record<string, string | number>; // The error response from the host
    host: 'top.gg' | 'dbl'; // The host that errored
});

webhookPost

@since 1.0.0

client.on('webhookPost', (client, stats, error) => {
    /* Emitted whenever an update post has happened */

    client: typeof Discord.Client; // The client after the post
    stats: Record<string, number>; // The stats used to post
    error: Record<string, string | number>; // The direct response of the host
    host: 'top.gg' | 'dbl'; // The host that posted
});

If your're using JavaScript, you can find out what Record<K, T> is. (spoiler alert, it's a more specific object)

Methods

hasVoted(userId, botId, token, host)

@since 1.2.0

Will return whether the user has voted or not.

nametype
userIdstring
botIdstring
tokenstring
hosttop.gg

Support

As far as languages go, TypeScript and JavaScript in both ESM and CJS should be supported.

Bot Lists

Plans

  • Support more bot lists
  • Support analytics
2.0.3

5 months ago

2.0.2

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago