Quick start
You need a server with Docker and a domain name pointing at it (for HTTPS), and a bot on discord.js 14.12 or later, or 15.
-
Start the collector
shardlens initwritesdocker-compose.yml, aCaddyfile, a.envwith generated secrets and keys, and abot.envholding the two settings your bot needs.Terminal window npx shardlens init --domain stats.example.com --app-id 123456789012345678cd shardlens && docker compose up -dCaddy gets a certificate for your domain, the collector creates its tables, and the dashboard is served at
https://stats.example.com. The bot’s two settings are inbot.env. -
Install the SDK in your bot
pnpm add @shardlens/discordjsnpm install @shardlens/discordjsyarn add @shardlens/discordjsbun add @shardlens/discordjs -
Add three lines to your bot
bot.ts import { createShardlens } from '@shardlens/discordjs';import { Client, GatewayIntentBits } from 'discord.js';const client = new Client({ intents: [GatewayIntentBits.Guilds] });createShardlens(client, {endpoint: process.env.SHARDLENS_URL!, // https://stats.example.comapiKey: process.env.SHARDLENS_INGEST_KEY!, // slk_ingest_…});await client.login(process.env.DISCORD_TOKEN);Copy the two lines from
bot.env(SHARDLENS_URLandSHARDLENS_INGEST_KEY) to wherever your bot reads its settings, then deletebot.env. -
Open the dashboard
Go to your domain and sign in with your read key (
SHARDLENS_READ_KEYin.env), or with Discord once you have set up Discord sign-in. Run a command in your bot: the live tiles on the Overview count it within seconds, and the chart and checklist follow within a minute or two, without reloading.
Next steps
Section titled “Next steps”- Configuration: every SDK option.
- Wrapping handlers: record handler time and errors.
- The
/privacycommand: let users opt out or ask for erasure. - What is collected: every field, generated from the wire format.