npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@discord-chat-exporter/core

v0.1.3

Published

TypeScript SDK for exporting Discord chat history

Readme

@discord-chat-exporter/core

TypeScript SDK for exporting Discord chat history to various formats.

npm License: MIT

Installation

npm install @discord-chat-exporter/core

Or with other package managers:

# pnpm
pnpm add @discord-chat-exporter/core

# yarn
yarn add @discord-chat-exporter/core

Requirements

  • Node.js >= 20.0.0
  • Discord authentication token (user or bot)

Quick Start

import {
  DiscordClient,
  ChannelExporter,
  ExportRequest,
  ExportFormat,
  Snowflake,
} from '@discord-chat-exporter/core';

// Initialize the client
const client = new DiscordClient('YOUR_DISCORD_TOKEN');

// Get channel and guild info
const channelId = Snowflake.parse('123456789012345678');
const channel = await client.getChannel(channelId);
const guild = await client.getGuild(channel.guildId);

// Create export request
const request = new ExportRequest({
  guild,
  channel,
  outputPath: './export.html',
  format: ExportFormat.HtmlDark,
});

// Export with progress callback
const exporter = new ChannelExporter(client);
await exporter.exportChannel(request, (progress) => {
  console.log(`Progress: ${progress.toFixed(1)}%`);
});

Export Formats

| Format | Enum Value | Extension | Best For | |--------|------------|-----------|----------| | HTML Dark | ExportFormat.HtmlDark | .html | Human reading (dark theme) | | HTML Light | ExportFormat.HtmlLight | .html | Human reading (light theme) | | JSON | ExportFormat.Json | .json | Data processing, archival | | CSV | ExportFormat.Csv | .csv | Spreadsheet analysis | | Plain Text | ExportFormat.PlainText | .txt | Simple text archives |

API Reference

DiscordClient

HTTP client for Discord API with rate limiting and retry logic.

const client = new DiscordClient(token);

// List guilds
for await (const guild of client.getUserGuilds()) {
  console.log(guild.name);
}

// List channels in a guild
for await (const channel of client.getGuildChannels(guildId)) {
  console.log(channel.name);
}

// Get direct message channels
for await (const dm of client.getDirectMessageChannels()) {
  console.log(dm.name);
}

ExportRequest Options

interface ExportRequestOptions {
  guild: Guild;                      // Required: Guild containing the channel
  channel: Channel;                  // Required: Channel to export
  outputPath: string;                // Required: Output file path or directory
  format: ExportFormat;              // Required: Export format

  // Optional filters
  after?: Snowflake | null;          // Only messages after this ID/date
  before?: Snowflake | null;         // Only messages before this ID/date
  messageFilter?: MessageFilter;      // Custom message filter

  // Optional features
  partitionLimit?: PartitionLimit;   // Split output by count or size
  shouldDownloadAssets?: boolean;    // Download media attachments
  shouldReuseAssets?: boolean;       // Reuse previously downloaded media
  assetsDirPath?: string;            // Directory for downloaded media

  // Formatting options
  shouldFormatMarkdown?: boolean;    // Enable markdown processing (default: true)
  locale?: string;                   // Locale for date/number formatting
  isUtcNormalizationEnabled?: boolean; // Normalize timestamps to UTC
}

Message Filtering

import { MessageFilter } from '@discord-chat-exporter/core';

// Parse filter expression
const filter = MessageFilter.parse('from:username has:attachment');

// Use in export request
const request = new ExportRequest({
  // ...
  messageFilter: filter,
});

Filter syntax:

  • from:username - Messages from specific user
  • has:attachment - Messages with attachments
  • has:embed - Messages with embeds
  • has:image - Messages with images
  • contains:text - Messages containing text
  • is:pinned - Pinned messages
  • Combine with and, or, - (not)

Partition Limits

import { PartitionLimit } from '@discord-chat-exporter/core';

// Split by message count
const countLimit = PartitionLimit.parse('1000');

// Split by file size
const sizeLimit = PartitionLimit.parse('10mb');

const request = new ExportRequest({
  // ...
  partitionLimit: sizeLimit,
});

Date Boundaries

import { Snowflake } from '@discord-chat-exporter/core';

// From specific date
const after = Snowflake.fromDate(new Date('2024-01-01'));

// From message ID
const afterId = Snowflake.parse('123456789012345678');

const request = new ExportRequest({
  // ...
  after,
  before: Snowflake.fromDate(new Date('2024-12-31')),
});

Exported Types

Core Classes

  • DiscordClient - API client
  • ChannelExporter - Export orchestrator
  • ExportRequest - Export configuration
  • Snowflake - Discord ID wrapper

Data Models

  • Guild, Channel, Message, User, Member
  • Role, Embed, Attachment, Reaction, Sticker

Enums

  • ExportFormat - Output formats
  • ChannelKind - Channel types
  • MessageKind - Message types

Utilities

  • MessageFilter - Filter expressions
  • PartitionLimit - Output splitting
  • FileSize - Byte size handling
  • Color - RGB color manipulation

Exceptions

  • DiscordChatExporterError - Base error
  • ChannelEmptyError - Empty channel (non-fatal)
  • UnsupportedChannelError - Unsupported channel type (fatal)

Authentication

User Token

  1. Open Discord in browser
  2. Press F12 for Developer Tools
  3. Go to Console tab
  4. Run: (webpackChunkdiscord_app.push([[''],{},e=>{m=[];for(let c in e.c)m.push(e.c[c])}]),m).find(m=>m?.exports?.default?.getToken!==void 0).exports.default.getToken()

Bot Token

  1. Create application at Discord Developer Portal
  2. Enable "Message Content Intent" in Bot settings
  3. Use the token from Bot settings

Related Packages

License

MIT