Overview
The module handles:- Posting formatted content to Discord channels
- Automatic message splitting for long content (2000 char limit)
- Custom webhook username and avatar
- Winner announcements with header formatting
- Rate limiting and error handling
No Discord bot required! Just create a webhook in your channel settings and add the URL to your environment.
Configuration
Environment Variables
Your Discord webhook URL (format:
https://discord.com/api/webhooks/...)Setup Instructions
- Navigate to your Discord channel
- Click the gear icon (Edit Channel)
- Go to Integrations β Webhooks
- Click New Webhook
- Copy the webhook URL
- Add to your
.envfile:
Configuration Functions
Core Functions
post_to_discord
Post raw content to Discord via webhook.Parameters
The message content to post. Supports Discord markdown formatting.Automatically splits into multiple messages if exceeds 2000 characters.
Display name shown for the webhook message
Optional URL for the webhook avatar image
Returns
True if all messages posted successfully, False otherwiseSuccess message with message count, or error description
Example
Message Splitting
Discord has a 2000 character limit per message. The function automatically:- Splits long content by event blocks (marked with
**Title**) - Ensures each chunk is under 1900 characters (safety margin)
- Posts multiple messages with 0.5 second delay between them
- Maintains block integrity (doesnβt split mid-event)
post_winner_announcement
Post a formatted winner announcement with header and artifact content.Parameters
The winning agent ID:
"alpha", "beta", "gamma", "delta", or "epsilon"The final winning score (0-100)
The Discord post markdown content generated by the winning agent
The original objective from the Dreamcatcher phase
Returns
True if announcement posted successfullySuccess confirmation or error description
Example
Header Format
The announcement includes an auto-generated header:Agent Name Mapping
Agent Alpha (The Speed Demon)
Agent Beta (The Perfectionist)
Agent Gamma (The Insider)
Agent Delta (The Crasher)
Agent Epsilon (The Hallucinator)
Error Handling
The module handles several error scenarios:Rate Limiting
The module implements basic rate limiting:- Delay Between Messages: 0.5 seconds
- Request Timeout: 10 seconds per message
- Automatic Retry: Not implemented (returns error on first failure)
Discord webhooks have rate limits. For high-volume posting, consider implementing exponential backoff or queuing.
Message Formatting
Supports full Discord markdown syntax:Testing
Test the Discord integration directly:- Load configuration from
.env - Check if webhook is configured
- Send a test message: βπ§ͺ Test message from Dream Foundry!β
Best Practices
Keep Webhook Secret: Never commit your webhook URL to version control. Use environment variables.
Message Length: Aim for under 1900 characters per logical block to avoid mid-content splits.
Formatting Preview: Test markdown formatting in Discord before automating, as rendering may differ slightly.
Error Handling: Always check the success return value before assuming the message was posted.