danbot-hosting-stats-poster
v1.0.0
Published
A stats poster for danbot-hosting bot API.
Downloads
31
Readme
danbot-hosting-stats-poster
Posts stats to Danbot Hosting's bot API.
Installation
NPM:
npm i danbot-hosting-stats-poster
Yarn:
yarn add danbot-hosting-stats-poster
Setting Up
- To start with posting stats, go to #bot-commands in the Discord Server and type
DBH!apikey
, the bot will send you your API key. - Use the API key in the examples provided below.
- Call the
autoPost()
function after you've instantiated a new AutoPoster client. - If everything went fine, your bot's stats will be posted to the API, and your bot will be added to the server if you want.
Examples
const { Client } = require("discord.js");
const AutoPoster = require("danbot-hosting-stats-poster");
const client = new Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const poster = new AutoPoster(client, {
key: "danbot-apikey", //replace this with your api key
});
client.on("ready", async () => {
console.log("logged in");
await poster.autoPost();
});
poster.on("autoPostingStarted", (post) => {
console.log(`Auto posting has started - ${post.statusText}`);
});
poster.on("post", (post) => {
console.log(`Posted to the API - ${post.status}`);
});
poster.on("error", (code, text, response) => {
console.log(`An error occured while posting -`, code, text, response);
});
client.login("your token");
Events
autoPostingStarted
(post) - Emitted when the AutoPoster starts posting to the API.posted
(post) - Emitted when the AutoPoster posts to the API everytime.error
(code, message, response) - Emitted when an error is occured while making a request to the API.
API
AutoPoster.constructor(client, AutoPosterOptions)
AutoPosterOptions
is an object which can contain the following:
- key (string) - The API key which you get from the bot (if you don't know where to get the API key, read this)
- guildCount (string, optional) - The guild count of the bot.
- userCount (string, optional) - The user count of the bot.
- postInterval (string, optional) - The interval (in milliseconds) to make posts at.
AutoPoster.autoPost()
This will start posting stats to the API and emit the autoPostingStarted
and posted
events.