Giter VIP home page Giter VIP logo

discordbotlist's Introduction

discordbotlist

Easily add support for voting and display your bot's stats on discordbotlist.com with just a few lines of code. This package provides support out of the box for discord.js and eris bots, but can easily be adapted to work with any library of your choosing.

Installation and Requirements

This package requires Node 16 or newer. If you're using discord.js v14, you should already meet this requirement. Install discordbotlist using:

npm i --save discordbotlist

Creating an API token

To post stats and fetch recent votes using this package, you'll need a discordbotlist API token. This is not your Discord bot token. Do not use your Discord bot token as an API token or webhook secret. To create an API token for your bot:

Setting up a Webhook Secret

To use webhooks, you will first need to create a Webhook Secret. This is not your Discord bot token. Do not use your Discord bot token as an API token or webhook secret. To configure your bot's Webhook Secret:

  • Visit its page on discordbotlist.com
  • Click the "Edit" button
  • Enter a value in the Webhook Secret input and click "Edit"

Creating a Client

For most, the easiest way to use this package will be by creating a client using the wrapper function for your library.

Creating a Client (discord.js)

import { createDjsClient } from "discordbotlist";
import { Client, GatewayIntentBits } from "discord.js";

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

client.on("ready", () => {
    const dbl = createDjsClient(DBL_API_TOKEN, client);
});

client.login(TOKEN);

Creating a Client (eris)

import { createErisClient } from "discordbotlist";
import { Client } from "eris";

const client = new Client(TOKEN, { intents: ["guilds"] });

client.on("ready", () => {
    const dbl = createErisClient(DBL_API_TOKEN, client);
});

client.connect();

Posting Bot Stats

After creating a client, you can start automatically posting your bot's stats to discordbotlist:

dbl.startPosting(/* optional interval, defaults to every hour */);

Setting up Voting

This package can be used to implement voting by either exposing a webhook endpoint discordbotlist will call, or periodically checking for recent votes. The former is recommended in most cases and should be preferred if it can be used for your bot.

Using Webhooks

This package provides express middleware that can be used to easily set up vote rewards using webhooks.

Using Webhooks (with a Client)

After creating a dbl client, it can be used to set up vote rewards with an event-based interface:

import express from "express";

const app = express();
app.use(express.json());

app.post("/dbl", dbl.webhook(DBL_WEBHOOK_SECRET));

dbl.on("vote", vote => {
    console.log(`${vote.username}#${vote.discriminator} voted!`);
});

app.listen(PORT);

Using Webhooks (no Client)

If you don't want to use a client, you can use the upvoteListener function instead:

import { upvoteListener } from "discordbotlist";
import express from "express";

const app = express();
app.use(express.json());

app.post(
    "/dbl",
    upvoteListener(DBL_WEBHOOK_SECRET, vote => {
        console.log(`${vote.username}#${vote.discriminator} voted!`);
    })
);

app.listen(PORT);

Using Polling

If you're running in an environment where webhooks aren't suitable, you can also support voting by using polling. To use polling, call Client#startPolling, then listen for the vote event just like webhooks:

dbl.startPolling(/* optional interval, defaults to every five minutes */);

dbl.on("vote", vote => {
    console.log(`${vote.username}#${vote.discriminator} voted!`);
});

Post Bot Commands

If your bot uses slash commands, you can display your bot's commands on DBL! You can post your commands to DBL the same way you post them to Discord. Use Client#postBotCommands to post your bot's commands:

dbl.postBotCommands([
    {
        name: "help",
        description: "View a list of the bot's commands.",
    },
]);

Discord Bot List API

This package also provides a strongly typed interface for interacting with DBL's REST API if desired. All types and functionality for this API wrapper is accessible from discordbotlist/api. For example, to manually post a bot's stats without a Client instance:

import { postBotStats } from "discordbotlist";

postBotStats(DBL_API_TOKEN, DISCORD_BOT_ID, {
    guilds: 100,
    users: 1000,
});

discordbotlist's People

Contributors

nickantx avatar

Watchers

 avatar  avatar

Forkers

cataclym

discordbotlist's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.