discord-analytics
Version:
A discord bot analytics to send your bot data
68 lines (67 loc) • 2.94 kB
TypeScript
import { DiscordAnalyticsOptions, TrackGuildType } from "../utils/types";
/**
* @class DiscordAnalytics
* @description The Discord.js class for the DiscordAnalytics library.
* @param {DiscordAnalyticsOptions} options - Configuration options.
* @property {any} options.client - The Discord.js client to track events for.
* @property {string} options.apiToken - The API token for DiscordAnalytics.
* @property {boolean} options.sharded - Whether the Discord.js client is sharded.
* @property {boolean} options.debug - Enable or not the debug mode /!\ MUST BE USED ONLY FOR DEVELOPMENT PURPOSES /!\
* @example
* const { default: DiscordAnalytics } = require('discord-analytics/discordjs');
* const { Client, IntentsBitField } = require('discord.js');
* const client = new Client({
* intents: [IntentsBitField.Flags.Guilds]
* })
* client.on('ready', () => {
* const analytics = new DiscordAnalytics({
* client: client,
* apiToken: 'YOUR_API_TOKEN'
* });
* analytics.trackEvents();
* });
* client.login('YOUR_BOT_TOKEN');
*
* // Check docs for more informations about advanced usages : https://docs.discordanalytics.xyz/get-started/installation/discord.js
*/
export default class DiscordAnalytics {
private readonly _client;
private readonly _apiToken;
private readonly _sharded;
private readonly _debug;
private readonly _headers;
private _isReady;
constructor(options: DiscordAnalyticsOptions);
/**
* Initialize DiscordAnalytics on your bot
* /!\ Advanced users only
* /!\ Required to use DiscordAnalytics (except if you use the trackEvents function)
* /!\ Must be used when the client is ready (recommended to use in ready event to prevent problems)
*/
init(): Promise<void>;
private statsData;
private calculateGuildMembersRepartition;
/**
* Track interactions
* /!\ Advanced users only
* /!\ You need to initialize the class first
* @param interaction - BaseInteraction class and its extensions only
* @param interactionNameResolver - A function that will resolve the name of the interaction
*/
trackInteractions(interaction: any, interactionNameResolver?: (interaction: any) => string): Promise<void>;
/**
* Track guilds
* /!\ Advanced users only
* /!\ You need to initialize the class first
* @param guild - The Guild instance only
* @param {TrackGuildType} type - "create" if the event is guildCreate and "delete" if is guildDelete
*/
trackGuilds(guild: any, type: TrackGuildType): Promise<void>;
/**
* Let DiscordAnalytics declare the events necessary for its operation.
* /!\ Not recommended for big bots
* /!\ Not compatible with other functions
* @param interactionNameResolver - A function that will resolve the name of the interaction
*/
trackEvents(interactionNameResolver?: (interaction: any) => string): void;
}