TH1/Tools/DiscordExport

Discord Chat Export

Local exporter for Discord channels using an official bot token and Discord's documented REST API.

Bot Setup

  1. Open the Discord Developer Portal and create an application.
  2. Add a bot to the application.
  3. Enable the bot's privileged Message Content Intent if you need message text, not just metadata.
  4. Invite the bot to your server with at least:
    • View Channels
    • Read Message History
  5. Make sure channel-specific permission overwrites allow the bot to read the target channels.

Do not use a user token or self-bot. Store the bot token only in your local environment.

Usage

PowerShell:

$env:DISCORD_BOT_TOKEN = "YOUR_BOT_TOKEN"
python Tools/DiscordExport/discord_export.py --channel 123456789012345678 --after 2026-07-01 --before 2026-07-02 --format jsonl --format csv
Remove-Item Env:\DISCORD_BOT_TOKEN

Multiple channels:

$env:DISCORD_BOT_TOKEN = "YOUR_BOT_TOKEN"
python Tools/DiscordExport/discord_export.py --channels-file Tools/DiscordExport/channels.example.txt --out output/discord-export
Remove-Item Env:\DISCORD_BOT_TOKEN

Date arguments are interpreted as UTC. A date without a time means the full UTC day for --before, and midnight UTC for --after.

Outputs

Supported formats:

  • jsonl: one normalized message per line, with the raw Discord message embedded.
  • json: the same normalized messages as a JSON array.
  • csv: spreadsheet-friendly summary with message text and attachment URLs.
  • md: human-readable Markdown transcript.

The default output directory is output/discord-export.

Notes

  • Discord returns messages newest-first; the exporter writes them oldest-first.
  • The exporter follows 429 rate-limit responses and also waits briefly between pages.
  • If content is empty, check the bot's Message Content Intent and channel permissions.
  • This tool exports messages the bot can legitimately access; deleted messages are not available through normal history export.