This is the documentation for the JavaScript wrapper for the Blist API. This documentation includes all information about installing and using the wrapper. This API requires your bot to be using discord.js and a Discord.Client()
instance.
To install the API wrapper, follow these simple steps:
- Open a command prompt in your bot's directory, or create a new directory and run
npm init
. - Run
npm i blist.javascript
. This will install the dependency and add it to your dependency list. - blist.js should now be successfully installed.
To create a new instance for the wrapper, we must first import the module. Once we imported the module, we can create a new instance. See the code example below. An API key is optional, but is required for multiple functions.
// Import the blist.js package
const blist = require("blist.javascript");
// Create a new blist instance
const client = new blist(bot, apiKey);
If you want to handle your bot votes, you can do so by creating a webhook.
// Create a new blist instance
const client = new blist(bot, apiKey);
const bot = new discordjs.Client();
bot.on("ready" => {
// Start a new webhook on port 4000, default port is 8000
client.startWebhook(4000);
// Optional
// client.startWebhook(PORT, {emit: "NAME", endpoint: "NAME"})
// bot.on("emit_name")
// http://URL:PORT/ENDPOINT_NAME
// Stop your webhook
client.stopWebhook();
});
// Detects when someone votes for your bot
bot.on("botVote", (vote) => console.log(vote));
// Login your bot
bot.login(token);
To fetch information and statistics about a user or a bot, you can use the following functions.
// Fetch bot stats
client.fetchBot(id).then((bot) => console.log(bot));
// Fetch user stats
client.fetchUser(id).then((user) => console.log(user));
To fetch the votes for your bot, this requires initializing a bot instance with an API key.
// Fetch bot votes, id is not required if discord.js bot client is provided on client creation
client.fetchVotes().then((votes) => console.log(votes));
Fetch the Discord.Client()
's bot reviews!
// Returns: {reviews: [Review_Objects]}
client.fetchReviews().then((reviews) => console.log(reviews));
To check if certain user(s) have voted, use this method!
// 1 user
client.hasVoted("USER_ID").then(v => console.log(v))
// Returns boolean
// multiple users
client.hasVoted(["USER_ID", "USER_ID", "USER_ID", "..ETC"]).then(ids => console.log(ids));
// Returns an array of user ids that have voted.
Posting bot stats requires you to provide an API key on client creation.
// Post bot stats, default
client.postStats().then(() => console.log("Posted stats succesfully!"));
// Provide the server_count and shards_count yourself.
client.postStats(server_count, shards_count).then(() => console.log(`Posted stats successfully!`));
Automatically post bot stats. Requires you to provide an API key on client creation.
// Start autoposting; the interval is in minutes
client.startAutopost(30).then(() => console.log("Now posting stats"));
client.stopAutopost().then(() => console.log("Stopped autoposting stats"));