Overview
The Message Archiving system logs all messages deleted through bulk purge operations, creating a permanent record for moderation review, appeals, or recovery. This ensures accountability and provides a safety net for accidental deletions.How It Works
When messages are purged using moderation commands:- The purge command collects messages to be deleted
- Before deletion, messages are logged to the archive
- Messages are stored with metadata (author, timestamp, content, attachments)
- A unique action ID links all messages from the same purge
- Messages are deleted from Discord
- Archive can be queried later for review
Only messages deleted through bulk purge commands are archived. Single message deletions by users are not logged.
Archived Data
Each archived message includes (messageLogger.ts:5):- Message ID: Original Discord message ID
- Content: Full text content (or
[NO TEXT CONTENT]if empty) - Author ID: Discord user ID of message sender
- Author Tag: Username#discriminator at time of purge
- Channel ID: Where the message was posted
- Channel Name: Channel name at time of purge
- Guild ID: Server ID
- Timestamp: When the message was originally sent
- Attachments: Array of attachment URLs
- Embeds: Serialized embed data
- Purged By: User ID who executed the purge
- Purged At: Timestamp of purge action
- Purge Action ID: Unique ID grouping messages from same purge
Storage Format
Messages are stored indata/purged_messages.json as a JSON array:
Action ID Grouping
ThepurgeActionId is a UUID generated for each purge operation. This allows you to:
- Retrieve all messages from a specific purge event
- Distinguish between different moderation actions
- Track which moderator performed which purge
Attachment URLs point to Discord’s CDN. These URLs may expire after a period of time, making old attachments inaccessible.
Usage in Purge Commands
Integrate message archiving into purge/bulk delete commands:Retrieving Archived Messages
Get All Archives for a Server
Get All Archives (All Servers)
Get Specific Purge Action
Implementation Details
Key Files
src/utils/messageLogger.ts- Message archiving system (messageLogger.ts:1)- Purge commands - Integration points
Data Directory Management
The system automatically creates the data directory if it doesn’t exist (messageLogger.ts:28):Error Handling
If the archive file is missing or corrupted:- Reading returns an empty array
- System continues to function
- New purges create a fresh archive file
Creating an Archives Command
You can create a command to view archived messages:Privacy Considerations
Data Retention
Archived messages are stored indefinitely by default. Consider:- Retention Policy: Delete archives older than X days/months
- User Requests: Provide a way for users to request their data
- Secure Storage: Ensure the data directory has appropriate file permissions
Access Control
Only trusted moderators should access the archives command:GDPR Compliance
If operating in EU/UK:- Inform users that deleted messages may be archived
- Provide data access requests
- Implement data deletion on request
- Include in privacy policy
Check your local laws regarding message retention and user data privacy.
Advanced Features
Archive Search
Implement search functionality:Export to File
Create downloadable archive exports:Archive Statistics
Generate purge statistics:Best Practices
- Regular backups: Back up the
purged_messages.jsonfile regularly - Size monitoring: Watch file size and implement rotation when needed
- Access logging: Log when moderators access archives
- Retention policy: Document how long archives are kept
- Attachment backup: Consider downloading attachments before URLs expire
- Audit trail: Keep records of archive access and modifications
Troubleshooting
Archive file growing too large
Implement file rotation:Messages not being archived
- Check the purge command calls
MessageLogger.logPurgedMessages()before deletion - Verify the data directory is writable
- Check bot logs for file write errors
- Ensure messages are being passed correctly (not null/undefined)
Cannot retrieve messages by action ID
Verify:- Action ID was generated and stored correctly
- Action ID is a valid UUID
- Messages were successfully written to the file
- No JSON corruption in the archive file