What This Workflow Does
This workflow runs every night at 9 PM to clean up older messages in a Discord server. It deletes messages that are older than seven days in all text and announcement channels. This stops message clutter and helps keep the server organized. The cleanup works without stopping if errors happen and respects Discord’s API limits.
Who Should Use This Workflow
Any Discord server owner or moderator with many messages piling up can use this. It is best for servers that want to remove old chats automatically to save time and avoid manual cleaning. Users need some basic knowledge of n8n and an authorized Discord bot with permission to read and delete messages.
Tools and Services Used
- n8n Automation Platform: To build and run the workflow.
- Discord API with OAuth2 credentials: To access channels and delete messages securely.
- Wait Nodes in n8n: To pause between API calls and avoid rate limit errors.
Inputs, Processing, and Output
Inputs
- Discord server ID (guild ID).
- Discord OAuth2 Bot credentials with permissions.
Processing Steps
- Trigger starts every night at 9 PM.
- Fetch all text and announcement channels in the server.
- Pause 2 seconds to avoid hitting API limits.
- Loop over each channel one at a time.
- Fetch all messages in the current channel.
- Pause 2 seconds again before fetching messages.
- Filter messages older than 7 days.
- Loop over each old message one by one.
- Delete each message, continuing even if some fail.
- Pause 1 second between each deletion to respect rate limits.
Output
- Discord server channels have no messages older than seven days.
- The server stays tidy and easier to manage.
- Automatic daily cleanup saves hours of manual work.
Beginner Step-by-Step: How to Use This Workflow in n8n
Import the Workflow
- Download the workflow file using the Download button on this page.
- Inside the n8n editor, click on “Import from File”.
- Select the downloaded workflow file to load it.
Configure Credentials
- In n8n, go to the credentials section and add your Discord OAuth2 Bot credentials.
- Make sure the bot has permissions to read channels, read messages, and delete messages in the server you want to clean.
- Update the node with your server guild ID if it is not already set.
Test and Activate
- Run the workflow manually once to check if it fetches channels and deletes test messages successfully.
- If it works fine, activate the workflow to run daily at 9 PM automatically.
If using self-host n8n or running on your own server, consider adjusting wait times based on your server size and API limits. See self-host n8n for hosting help.
Customization Ideas
- Change the message retention period by editing the filter node to a different number of days.
- Modify the channel filter to select only specific channels by name or type.
- Add error notification using a separate workflow that triggers if deleting messages fails.
- Adjust wait node durations to balance speed vs. preventing rate limits based on your server size.
Handling Errors and Rate Limits
- If rate limit errors happen, increase wait node pauses between API calls.
- If unauthorized errors appear, check your Discord OAuth2 credentials and make sure permissions are correct.
- If messages don’t delete, verify the bot role has message deletion rights in each channel.
- Enable “continue on error” options in delete message nodes to stop full workflow from crashing.
Summary of Results
✓ The workflow cleans up all messages older than seven days every night.
✓ It runs safely without manual work and respects Discord API limits.
✓ Keeps the Discord server tidy and improves usability.
✓ Saves hours of manual cleaning for moderators.

