A collection of Python scripts for Discord data collection, trust analysis, and social ranking.
| Script | Description |
|---|---|
read_messages.py |
Collects messages from Discord servers |
generate_trust.py |
Calculates trust values between users |
check_channels.py |
Shows all channels the bot has access to with permissions |
find_mods.py |
Finds moderators and administrators in Discord servers |
load_discord_data.py |
Loads collected Discord data into a PostgreSQL database |
process_scores.py |
Processes score files with transformations (log, sqrt, quantile) |
process_seed.py |
Processes seed score CSV files with tier-based weighting |
generate_json.py |
Generates JSON files for the UI from seed and score data |
summarize_posts.py |
Summarizes channel posts using OpenAI GPT |
python3 -m venv venv
source ./venv/bin/activatepip install -r requirements.txtDependencies:
discord.py- Discord API wrapperpython-dotenv- Environment variable managementtoml- Configuration file parsingpandas- Data processingscipy- Scientific computing (for score transformations)openai- OpenAI API (for post summarization)psycopg2- PostgreSQL adapter (for database operations)
cp .env.example .env
# Edit .env and add your tokensRequired environment variables:
DISCORD_TOKEN- Your Discord bot tokenDISCORD_CLIENT_ID- Your Discord application client ID (optional)DATABASE_URL- PostgreSQL connection string (for database scripts)OPENAI_API_KEY- OpenAI API key (for summarization)
[settings]
output_folder = "raw"
default_days = 730
max_messages_per_channel = 20000
channel_delay = 1
server_delay = 5
[exclusions]
exclude_channel_ids = [
"channel_id_to_exclude",
]
[trust]
mention_points = 50
reply_points = 40
reaction_points = 30
here_points = 10
everyone_points = 10
role_points = 10
[servers]
server_ids = [
"1021933844481445989", # Your server ID
"another_server_id", # Add more servers
]# Verify which channels the bot can access
python check_channels.py# List all moderators and admins in servers
python find_mods.py
python find_mods.py --verbose # Show detailed role information# Process all servers from config.toml
python read_messages.py
# Override settings via command line
python read_messages.py --days 30 --max-messages 1000# Calculate trust from collected messages
python generate_trust.py
# Use custom input path
python generate_trust.py --input raw# Load collected JSON data into PostgreSQL
python load_discord_data.py# Process scores with log transformation (default)
python process_scores.py
# Use square root transformation
python process_scores.py --sqrt
# Use quantile transformation
python process_scores.py --quantile# Process seed CSV with default tier weights (60%, 20%, 20%)
python process_seed.py seed/my_seed.csv
# Custom tier weights
python process_seed.py seed/my_seed.csv --weights 0.5 0.3 0.2# Generate JSON files for the UI
python generate_json.py# Generate AI summaries for channel posts
python summarize_posts.pysocialrank/
├── raw/ # Raw Discord message data (JSON)
├── trust/ # Trust score CSVs per server
├── scores/ # Score files for processing
├── output/ # Processed score output
├── seed/ # Seed data CSVs
├── ui/ # Generated JSON for UI
├── schemas/ # SQL schema definitions
├── migrations/ # Database migrations
├── config.toml # Main configuration file
├── requirements.txt # Python dependencies
└── *.py # Python scripts
Messages saved as ServerName.json with structure:
{
"server_info": { "id": "...", "name": "..." },
"channels": {
"channel_id": {
"channel_info": { "name": "..." },
"messages": [...]
}
}
}User ID mappings saved as user_ids_ServerName.csv.
Trust scores saved as CSV files per server (e.g., karma3_labs.csv):
i,j,v
user_id_1,user_id_2,150
user_id_1,user_id_3,80Where:
i= user ID giving trustj= user ID receiving trustv= trust value (sum of all interactions)
Transformed and normalized scores with usernames:
i,v
username1,1000.00
username2,850.50Combined seed and score data for the UI:
{
"category": "socialrank",
"server": "server_id",
"seed": [{"i": "username", "v": 0.6}],
"scores": [{"i": "username", "v": 950.0}]
}| Interaction | Points |
|---|---|
| Direct mention (@user) | 50 |
| Reply to message | 40 |
| React to message | 30 |
| Use @here | 10 (to everyone) |
| Use @everyone | 10 (to everyone) |
| Use @role | 10 (to role members) |
Note: Bots are excluded from giving or receiving trust values.
The project includes PostgreSQL migrations in migrations/ and schemas in schemas/ for storing:
- Servers, channels, and users
- Messages with attachments, embeds, and reactions
- Mentions and role mentions
- Computed scores
- Channel summaries (AI-generated)
If the bot can't read messages:
- Run
python check_channels.pyto see access status - Ensure the bot has "View Channel" and "Read Message History" permissions
- Enable required intents in Discord Developer Portal
For find_mods.py, enable "Server Members Intent" at:
https://discord.com/developers/applications/
Ensure DATABASE_URL is set correctly:
postgresql://user:password@host:port/database