Discord Fetch
Why Discord Fetch?
Discord conversations contain valuable knowledge, but Discordβs UI makes it hard to: - Export community discussions for analysis - Archive important conversations before theyβre lost
- Process messages with LLMs or data tools - Search across multiple channels efficiently
Discord Fetch solves this by providing a simple interactive CLI that exports Discord messages to clean JSON files, removing all the complexity of Discordβs API.
Installation
pip install discord-fetch
Or install from source:
git clone https://github.com/hamelsmu/discord_fetch.git
cd discord_fetch
pip install -e .
Before using this tool, you need to create a Discord bot and obtain a token:
1. Create a Discord Application
- Go to the Discord Developer Portal
- Click βNew Applicationβ and give it a name
- Navigate to the βBotβ section in the sidebar
- Click βAdd Botβ
- Under the βTokenβ section, click βCopyβ to get your bot token
2. Required Bot Permissions
Your bot needs the following permissions: - View Channels - To see the channels in the server - Read Message History - To fetch historical messages - Read Messages/View Channels - Basic read access
3. Bot Scopes and OAuth2
When inviting your bot to a server, use these scopes:
bot
- Basic bot permissionsapplications.commands
(optional) - If you plan to add slash commands
4. Invite the Bot to Your Server
- In the Discord Developer Portal, go to βOAuth2β > βURL Generatorβ
- Select the
bot
scope - Select the required permissions listed above
- Copy the generated URL and open it in your browser
- Select the server you want to add the bot to
5. Environment Setup
Create this environment variable
DISCORD_TOKEN=your_bot_token_here
Getting Started in 2 Minutes
Once youβve set up your Discord bot (see setup section below), using Discord Fetch is simple:
# Install the tool
pip install discord-fetch
# Set your bot token
export DISCORD_TOKEN=your_bot_token_here
# Run the interactive CLI
discord-fetch
The CLI will guide you through:
- Selecting a Discord server from your botβs servers
- Choosing channels to export (one, multiple, or all)
- Picking output format (single combined file or separate files)
- Watching progress with live progress bars
Thatβs it! Your Discord messages are now in clean JSON files ready for processing.
Live example
What You Can Do With Discord Fetch
π― For Quick Channel Exports
Use the interactive CLI when you want to: - Export specific channels from a Discord server - Archive channels before theyβre deleted - Get data for one-time analysis
Example: Export your projectβs #general and #dev channels
discord-fetch
# Select your server, choose specific channels, export to JSON
π For Bulk Server Exports
Perfect when you need to: - Archive an entire Discord server - Migrate community knowledge to another platform - Create regular backups of all channels
Example: Export all 84 channels from a large community
discord-fetch
# Select server, choose "ALL CHANNELS", save to directory
π§ For Custom Integrations
Use the Python API when you need: - Automated exports on a schedule - Custom filtering or processing - Integration with other Python tools
Example: Auto-export new messages daily
from discord_fetch.core import fetch_messages_since_date
from datetime import datetime, timedelta
# Fetch only messages from last 24 hours
= datetime.now() - timedelta(days=1)
yesterday = await fetch_messages_since_date(channel_id, yesterday) messages
See It In Action
Hereβs what the interactive CLI looks like:
$ discord-fetch
Discord Channel Fetcher
Available Guilds:
1. AI Evals For Engineers & Technical PMs (84 channels)
2. LangChain Community (126 channels)
3. OpenAI DevDay (45 channels)
Select guild number [1]: 1
Channels in AI Evals For Engineers & Technical PMs:
ββββββ³βββββββββββββββββββββββββββββββββ³βββββββββββββββββββ³ββββββββββββββββββββ
β # β Channel β Category β ID β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β 0 β ALL CHANNELS β β β β β
β 1 β general β Text Channels β 136866639069682...β
β 2 β announcements β Text Channels β 137615200096996...β
β 3 β introductions β Text Channels β 137655886438386...β
β 4 β course-discussions β Course β 138234567891234...β
ββββββ΄βββββββββββββββββββββββββββββββββ΄βββββββββββββββββββ΄ββββββββββββββββββββ
Select channel number (0 for all) [0]: 0
Selected: All 84 channels
Output Options:
1. Concatenate to single file
2. Separate files in directory
Select output option [1]: 2
Enter output directory [./discord_output]: ./ai-evals-export
#general β Έ ββββββββββββββββββββββββββββββββββββββββ 100/100 β Complete
#announcements β Ό ββββββββββββββββββββββββββββββββββββββββ 100/100 β Complete
#introductions β ΄ ββββββββββββββββββββββββββββββββββββββββ 100/100 β Complete
#course-discussions β ¦ βββββββββββββββββββββββββββββββββββββββ 47/100 Fetching...
Total β § βββββββββββββββββββββββββββββββββββββββ 4/84 4/84 completed
β Saved 84 files to ./ai-evals-export
Successfully fetched 84 out of 84 channels!
Which Tool Should I Use?
Use discord-fetch
(Interactive CLI) when:
β
You want a guided experience with visual feedback
β
Youβre exporting channels for analysis or archival
β
You need to browse and select from available channels
β
Youβre not familiar with Discord channel IDs
Use fetch_discord_msgs
(Direct CLI) when:
β
You know the exact channel ID to export
β
You want to pipe output directly to another tool
β
Youβre scripting or automating exports
β
You need stdout output for processing
Use the Python API when:
β
You need custom filtering or processing logic
β
Youβre building a larger application
β
You want to fetch only new messages since a date
β
You need programmatic access to the data
Quick decision: If youβre unsure, start with discord-fetch
- itβs the easiest way to get started!
Advanced Python API
For developers who need programmatic access:
Basic Channel Export
from discord_fetch.core import fetch_discord_msgs
import asyncio
# Export a single channel
= 1369370266899185746
channel_id = await fetch_discord_msgs(
original, simplified
channel_id, =False, # Don't save to file
save_original=False, # Don't save to file
save_simplified=False # Silent operation
print_summary )
List All Available Channels
from discord_fetch.core import list_all_channels
# Get all channels your bot can see
= await list_all_channels()
channels for ch in channels:
print(f"{ch['guild_name']} - #{ch['channel_name']} ({ch['channel_id']})")
Fetch Only New Messages
from discord_fetch.core import fetch_messages_since_date
from datetime import datetime, timedelta
# Get messages from last 7 days
= datetime.now() - timedelta(days=7)
last_week = await fetch_messages_since_date(channel_id, last_week) recent
Find Active Channels
from discord_fetch.core import list_channels_with_new_messages
# Find channels with activity since a date
= await list_channels_with_new_messages("01-01-2024")
active for guild, data in active.items():
for ch in data['channels_with_new_messages']:
print(f"{ch['channel_name']}: {ch['new_message_count']} new messages")
Understanding the Output Format
Discord Fetch simplifies complex Discord data into clean JSON:
Original Format (with metadata)
{
"channel_info": {...},
"messages": [
{
"id": "123456789",
"author": {...},
"content": "Message text",
"timestamp": "2024-01-15T10:30:00",
"attachments": [...],
"reactions": [...],
"reply_to": {...}
}
],
"threads": {...}
}
Simplified Format (for processing)
{
"channel": "general",
"conversations": [
{
"main_message": {
"author": "alice",
"content": "Has anyone tried the new API?"
},
"replies": [
{
"author": "bob",
"content": "Yes! It's much faster now"
},
{
"author": "charlie",
"content": "Agreed, the response time improved by 50%"
}
]
}
]
}
The simplified format: - Groups related messages into conversations - Removes IDs, timestamps, and metadata - Reduces file size by ~75% - Perfect for LLMs and analysis tools