Plugin for @sapphire/framework to post and manage bot stats with Statcord.
This plugin allows the integration of Statcord with the Bot. Statcord is a web page that allows to manage statistics such as, how many commands were executed in a day, new guilds, etc.
More information about Statcord can be found on its website.
- Fully ready for TypeScript!
- Includes ESM ready entrypoint
- Easy to use
@kaname-png/plugin-statcord
depends on the following packages. Be sure to install these along with this package!
You can use the following command to install this package, or replace npm install
with your package manager of choice.
npm install @kaname-png/plugin-statcord @sapphire/framework discord.js
In your main or setup file, register the plugin:
require('@kaname-png/plugin-statcord/register');
It is important to add an API key provided by Statcord.
require('@kaname-png/plugin-statcord/register');
const client = new SapphireClient({
/* your bot options */
statcord: {
client_id: 'YOUR_BOT_ID', // (Optional) By default it is the bot id.
key: 'YOUR_AWESOME_API_KEY', // (Required) Statcord API key.
autopost: false, // (Optional) Allows automatic posting of statistics.
baseUrl: 'https://api.statcord.com/v3', // (Optional) Change the base URL of the Statcord API.
debug: false, // (Optional) Show debug messages.
sharding: false // (Optional) Activate the sharding mode, it is important to read the notes below.
}
});
async function main() {
await client.login();
}
void main();
In your main or setup file, register the plugin:
import '@kaname-png/plugin-statcord/register';
It is important to add an API key provided by Statcord.
import '@kaname-png/plugin-statcord/register';
const client = new SapphireClient({
/* your bot options */
statcord: {
client_id: 'YOUR_BOT_ID', // (Optional) By default it is the bot id.
key: 'YOUR_AWESOME_API_KEY', // (Required) Statcord API key.
autopost: false, // (Optional) Allows automatic posting of statistics.
baseUrl: 'https://api.statcord.com/v3', // (Optional) Change the base URL of the Statcord API.
debug: false, // (Optional) Show debug messages.
sharding: false // (Optional) Activate the sharding mode, it is important to read the notes below.
}
});
async function main() {
await client.login();
}
void main();
If you enable the autopost
option, that's it, the plugin will collect and publish the statistics for you, you don't have to do anything else!
To set the bandwidth usage in each statistics post the setBandwidthUsage()
method is available, the data sent by this method is reset in each statistics post. This is done so that the user can choose the best way to get this data.
const { container } = require('@sapphire/framework');
class MyAwesomeServicePostStats {
public postBandwidth() {
const bandwidthUsage = getBandwidthUsage(); // Use your method to get this data.
container.statcord.setBandwidthUsage(bandwidthUsage);
}
}
export default MyAwesomeServicePostStats;
import { container } from '@sapphire/framework';
export class MyAwesomeServicePostStats {
public postBandwidth() {
const bandwidthUsage = getBandwidthUsage(); // Use your method to get this data.
container.statcord.setBandwidthUsage(bandwidthUsage);
}
}
To be able to post statistics manually, it is necessary to disable the autopost
option in the statcord options, by default it is disabled.
const client = new SapphireClient({
/* your bot options */
statcord: {
key: 'YOUR_AWESOME_API_KEY',
autopost: false
}
});
async function main() {
await client.login();
}
void main();
import '@kaname-png/plugin-statcord/register';
const client = new SapphireClient({
/* your bot options */
statcord: {
key: 'YOUR_AWESOME_API_KEY',
autopost: false
}
});
async function main() {
await client.login();
}
void main();
In order to be able to post statistics there is the postStats
method available, by default, the statistics of used commands, popular commands, total guilds and users are managed internally by the plugin.
Remember that you can use these methods and all the Statcord plugin methods globally available anywhere in the Bot.
const { container } = require('@sapphire/framework');
class MyAwesomeServicePostStats {
public postStats() {
container.statcord.postStats();
}
}
export default MyAwesomeServicePostStats;
import { container } from '@sapphire/framework';
export class MyAwesomeServicePostStats {
public postStats() {
container.statcord.postStats();
}
}
The plugin allows to get the statistics from Statcord, as it also has methods that wrapper with the Statcord API.
clientStats();
: Get current client statistics in Statcord.bucketStats();
: Check everyone who has voted for the bot today.userVotesStats();
: Check if someone has voted for the bot today.
- The
postCommand
andpostStats
methods are available globally so that they can be used in other ways according to the user's needs. For example, it is recommended to disable theautopost
option when using the ShardingManager, as it is possible for Shards to go into Rate Limit in the Statcord API when they all perform the action of posting statistics at the same time and having these methods available allows you to devise a better way to post those statistics. - If the
sharding
mode is used together with theautopost
option it is important that the Shards have at least 1 minute of initialization between them, so that the shards have a difference of1 minute
and thus be able to send the statistics without entering Rate Limit in the Statcord API.
Thanks goes to these wonderful people (emoji key):
Kaname 💻 🐛 📖 🚇 🚧 👀 |
Sebazz 🐛 💻 |
Chiko 🐛 💻 |
Williams Bussat 💻 📖 🤔 |
Davide Trinastich 💻 🤔 |
This project follows the all-contributors specification. Contributions of any kind welcome!