# How to Automate Discord Server Moderation using the API

- Tool: API Automations
- Difficulty: Advanced
- Fix time: 1-2 hours
- Compatibility: Free — requires MESSAGE_CONTENT privileged intent (Developer Portal toggle below 75 guilds; apply at 75+, required verification at 100+)
- Last updated: May 2026

## TL;DR

Automate Discord server moderation by receiving MESSAGE_CREATE Gateway events (requires MESSAGE_CONTENT privileged intent), checking content against rules, then calling PATCH /guilds/{guild.id}/members/{user.id} to timeout (up to 28 days via communication_disabled_until), DELETE /guilds/{guild.id}/members/{user.id} to kick, or PUT /guilds/{guild.id}/bans/{user.id} to ban. The MESSAGE_CONTENT intent requires Developer Portal approval — bots in 75+ servers must apply, 100+ requires verification.

## Best practices

- Start conservative: timeout-only for all violations, review logs for a week before enabling kicks or bans.
- Implement progressive escalation stored in a database — first violation gets a 1-hour timeout, second gets 24 hours, third gets a ban.
- Never auto-moderate the guild owner — they are immune to all bot actions. Always check if the target is the guild owner before attempting any action.
- Build a manual override command (/modstop) that disables automated actions and alerts human mods to take over.
- Separate spam detection (message rate, identical content) from content filtering (banned words) — they have different false positive profiles and may need different severity levels.
- Test moderation rules in a private test server with fake spam accounts before deploying to a real community.
- Implement the circuit breaker pattern: pause all automated actions after 20 actions per minute to protect against the 10,000 invalid request Cloudflare threshold.

## Frequently asked questions

### Is the Discord moderation API free?

Yes. All Discord REST API calls (timeout, kick, ban, message delete) are free. The MESSAGE_CONTENT privileged intent is also free but requires a Developer Portal toggle and verification at 100+ guilds.

### What happens if I hit the Discord rate limit during a raid?

You receive HTTP 429 with retry_after in seconds. If X-RateLimit-Global is true, all endpoints are blocked. Critically: 10,000 requests returning 401/403/429 within 10 minutes triggers a temporary Cloudflare ban of approximately 1 hour. Implement a circuit breaker to pause automated moderation when action rates spike.

### Can my bot moderate the guild owner?

No. The guild owner is always at the top of the role hierarchy and is immune to all bot moderation actions — even from a bot with Administrator permission. Any attempt to timeout, kick, or ban the guild owner returns 403.

### Why is message.content empty in my MESSAGE_CREATE handler?

The MESSAGE_CONTENT intent (became privileged Aug 31, 2022) is not enabled. You must toggle it on in Developer Portal > Bot > Privileged Gateway Intents AND set intents.message_content = True in discord.py or include GatewayIntentBits.MessageContent in discord.js. Both are required.

### What is the maximum timeout duration?

28 days (2,419,200 seconds). Set communication_disabled_until to a future ISO 8601 timestamp no more than 28 days from now. For indefinite restrictions, use a ban instead. Setting the timestamp to null removes an active timeout.

### Can I use Discord's built-in AutoMod instead of building a custom bot?

For common patterns (keyword matching, spam, mention limits), Discord's native AutoMod is excellent — it runs server-side with no API quota consumption. Reach it via POST /guilds/{id}/auto-moderation/rules. Custom bots are better for complex rules, external data lookups (e.g., checking a URL against a known scam list), and progressive escalation logic.

### Can RapidDev help build a custom Discord moderation system?

Yes. RapidDev has built 600+ apps including Discord moderation bots with raid protection, AI-powered spam detection, and appeals management. Visit rapidevelopers.com for a free consultation.

### Can I ban a user who already left the server?

Yes. PUT /guilds/{guild.id}/bans/{user.id} works for users who are not current members — it adds them to the ban list so they cannot rejoin. This is useful for banning known raid participants even after they leave.

---

Source: https://www.rapidevelopers.com/api-automations/how-to-automate-discord-server-moderation-using-the-api
© RapidDev — https://www.rapidevelopers.com/api-automations/how-to-automate-discord-server-moderation-using-the-api
