# How to Automate Twitch Chat Moderation using the API

- Tool: API Automations
- Difficulty: Advanced
- Fix time: 1-2 hours
- Compatibility: User Access Token from a broadcaster or moderator account. Requires moderator:manage:banned_users and moderator:manage:chat_messages scopes. The moderator account must be actively appointed as a mod in the channel.
- Last updated: May 2026

## TL;DR

Automate Twitch chat moderation using POST /moderation/bans for timeouts and bans, DELETE /moderation/chat to delete messages, and the channel.chat.message EventSub subscription to read chat in real time. IRC chat commands (/ban, /timeout) were deprecated February 18, 2023 and tmi.js v1 is unmaintained — use Helix REST endpoints with a User Access Token carrying moderator:manage:banned_users and moderator:manage:chat_messages scopes.

## Best practices

- Use EventSub WebSocket (channel.chat.message) to read chat — never IRC chat commands, which were deprecated February 18, 2023, or tmi.js v1, which is unmaintained
- Implement a circuit breaker that pauses moderation at 400 actions/minute to leave headroom below the 800/min Helix rate limit during spam raids
- Run moderation actions in an async queue, not synchronously in the message loop — this prevents the bot from falling behind during high-traffic periods
- Validate User Access Tokens hourly and refresh before the ~60-day expiry — users can revoke at any time, and a revoked token returns 401 on every moderation call
- Filter your own bot account and the broadcaster user ID before any moderation call — attempting to act on them returns 422 errors
- Log all automated moderation actions with user_id, reason, and timestamp to an audit database for transparency and appeal handling

## Frequently asked questions

### Can I still use /ban and /timeout commands via IRC or tmi.js?

No. IRC chat moderation commands (/ban, /timeout, /clear, etc.) were deprecated February 18, 2023 and no longer function. tmi.js v1 has not had a new npm release since July 2022 and explicitly warns about this on its homepage. Use POST /moderation/bans (for bans/timeouts) and DELETE /moderation/chat (for message deletion) via Helix REST with a User Access Token carrying the correct scopes.

### Does the bot need to be an actual moderator in the channel?

Yes. The user whose token is used in moderator_id must be an active moderator in the broadcaster's channel. The broadcaster appoints mods by running /mod <username> in their channel. If the mod status is removed while the bot is running, all moderation calls return 403. Monitor for 403 errors and alert your team when this happens.

### What scopes does the User Access Token need?

At minimum: moderator:manage:banned_users (for POST /moderation/bans) and moderator:manage:chat_messages (for DELETE /moderation/chat). For reading chat via EventSub WebSocket, add user:read:chat. You need user:write:chat to send messages. Always request the minimal set of scopes needed.

### How do I handle spam raids without exhausting the rate limit?

Implement a circuit breaker that pauses at 400 moderation actions per minute — half the 800/min Helix bucket. This leaves headroom so the bot stays operational throughout the raid. Also prioritize banning/timing out repeat offenders over deleting individual messages — removing a user from chat is more effective than deleting each of their messages.

### Can I use an App Access Token instead of a User Access Token for moderation?

No. POST /moderation/bans and DELETE /moderation/chat require a User Access Token from an account with active moderator status in the channel. App Access Tokens (from Client Credentials flow) are not user-specific and cannot perform moderation actions on behalf of a moderator.

### Is the Twitch API free to use?

Yes, the Twitch Helix API and EventSub are free with no per-request charges. You need a free Twitch developer account and a registered application at dev.twitch.tv/console/apps.

### Can RapidDev help build a custom Twitch moderation bot?

Yes. RapidDev has built 600+ apps including Twitch moderation systems, multi-channel dashboards, and real-time stream bots. Book a free consultation at rapidevelopers.com.

---

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