---
title: Automatic Moderation Rules
short_name: Automatic Moderation Rules
---
import Callout from "@/components/Alerts/Callout";
import { ConfigOption } from "@/components/MDX/ConfigOption";
# Automatic Moderation Rules
Automatic Moderation Rules, or Moderation Rules (or simply "rules"), are a set of rules that are used to automatically moderate messages and user profiles in your server. These rules are used to filter out messages and user profiles that violate the rules you've set up.
## What are Moderation Rules and how do they work?
Moderation Rules are defined inside the guild-specific configuration file, and each rule may have an associated trigger condition and actions on trigger, alongside other behavior-controlling options.
Moderation Rules are **order-specific**, that means, the order in which the rules are defined in the configuration file matters. The first rule that matches the trigger condition will be executed, and the rest of the rules may or may not be ignored depending on the rule's configuration.
## Configuring Moderation Rules
To configure Moderation Rules, you need to edit the guild-specific configuration file. The configuration file is located at `config/config.json`.
The object you should add/edit is `rule_moderation`. For example, a Moderation Rule configuration might look like this:
```json
{
// This key is the Guild ID!
"847638624836373764": {
"rule_moderation": {
"enabled": true,
"rules": [
{
"type": "word_filter",
"words": ["word1", "word2"],
"actions": [{ "type": "delete_message" }]
},
{
"type": "regex_filter",
"patterns": ["disc(o|0)rd\\.gg"],
"actions": [{ "type": "delete_message" }]
}
]
}
}
}
```
We’ll explain the configuration options in the next section.
## Rule Attributes
Each rule is an object defined inside the `rule_moderation.rules` array. The following attributes are available for each rule:
word_filter
regex_filter
anti_invite
domain_filter
mime_type_filter
file_extension_filter
repeated_text_filter
mass_mention_filter
image_filter
embed_filter
profile_filter
ai_scan
file_filter
}
>
The type of the rule.
The name of the rule. This is optional and is used for identification
purposes.
Whether the rule is enabled or not. If this is set to `false`, the rule will
be ignored.
normal
inverse
}
optional
defaultValue={`"normal"`}
>
The mode of the rule. If set to `inverse`, the rule will be triggered when
the trigger condition is not met.
Whether to stop processing the rules after this rule is triggered. If this
is set to `false`, the next rule will be processed even if this rule is
triggered.
ModerationAction
}
>
An array of actions to perform when the rule is triggered. Each action is a
`ModerationAction` object.
MessageRuleCondition
}
>
The condition that must be met for the rule to be triggered. This is an
object that defines the condition.
MessageRuleCondition
}
>
The condition that must be met for the rule to be ignored. This is an object
that defines the condition.
Whether this is a bypasser.
A bypasser is a special type of rule. When a bypasser matches, it will ignore specific rules as defined in the `bypasses` option.
string
}
>
An array of rule names that this rule bypasses.
This option is only used when `is_bypasser` is set to `true`.
There might be additional attributes depending on the rule type.
## Rule Types
### Word Filter
The Word Filter rule type is used to filter messages based on specific words or tokens. The rule will trigger if any of the words in the `words` array are found or any of the tokens in the `tokens` array are found.
Tokens are a way to match a word or a part of a word. For example, the token `word` will match `word`, `words`, `wording`, etc.
However, the token `word` will not match `w ord`, `wo rd`, etc.
A word is matched if it is surrounded by spaces or the beginning/end of the message. For example, the word `word` will match `word`, `word ing`, etc., but not `sword`, `wordy`, etc.
Example configuration for a Word Filter rule:
```json
{
"type": "word_filter",
"words": ["word1", "word2"],
"tokens": ["token1", "token2"],
"actions": [
{ "type": "warn", "reason": "Automatic: Posted a blocked word" },
{ "type": "delete_message" },
]
}
```
**Options specific to Word Filter**
string
}
>
An array of words to filter.
string
}
>
An array of tokens to filter.
Whether to normalize the words, tokens, and the message before filtering.
### Regex Filter
The Regex Filter rule type is used to filter messages based on regular expressions. The rule will trigger if any of the patterns in the `patterns` array are found.
Example configuration for a Regex Filter rule:
```json
{
"type": "regex_filter",
"patterns": ["disc(o|0)rd\\.gg"],
"actions": [
{ "type": "warn", "reason": "Automatic: Posted a Discord invite link" },
{ "type": "delete_message" },
]
}
```
**Options specific to Regex Filter**
string
string
RegexFlagString
}
>
An array of regular expressions to filter.
A `RegexFlagString` is a string that contains the flags for the regular expression, supported by JavaScript.
### Anti-Invite
The Anti-Invite rule type is used to filter messages that contain invite links. The rule will trigger if an invite link is found in the message.
Example configuration for an Anti-Invite rule:
```json
{
"type": "anti_invite",
"actions": [
{ "type": "warn", "reason": "Automatic: Posted a Discord invite link" },
{ "type": "delete_message" },
]
}
```
**Options specific to Anti-Invite**
string
}
>
An array of invite codes that are allowed.
Whether to allow internal server invites.
### Domain Filter
The Domain Filter rule type is used to filter messages that contain URLs with specific domains. The rule will trigger if a URL with a domain in the `domains` array is found in the message.
Example configuration for a Domain Filter rule:
```json
{
"type": "domain_filter",
"domains": ["example.com", "example.org"],
"actions": [
{ "type": "warn", "reason": "Automatic: Posted a blocked domain" },
{ "type": "delete_message" },
]
}
```
**Options specific to Domain Filter**
string
}
>
An array of domains to filter.
Whether to scan only the links in the message.
### MIME Type Filter
The MIME Type Filter rule type is used to filter messages that contain attachments with specific MIME types. The rule will trigger if an attachment with a MIME type in the `mime_types` array is found in the message.
Example configuration for a MIME Type Filter rule:
```json
{
"type": "mime_type_filter",
"data": ["image/png", "image/jpeg"],
"actions": [
{ "type": "warn", "reason": "Automatic: Posted a file that is not allowed" },
{ "type": "delete_message" },
]
}
```
**Options specific to MIME Type Filter**
string
}
>
An array of MIME types to filter.
### File Extension Filter
The File Extension Filter rule type is used to filter messages that contain attachments with specific file extensions. The rule will trigger if an attachment with a file extension in the `extensions` array is found in the message.
Example configuration for a File Extension Filter rule:
```json
{
"type": "file_extension_filter",
"data": ["png", "jpg"],
"actions": [
{ "type": "warn", "reason": "Automatic: Posted a file that is not allowed" },
{ "type": "delete_message" },
]
}
```
**Options specific to File Extension Filter**
string
}
>
An array of file extensions to filter.
### Repeated Text Filter
The Repeated Text Filter rule type is used to filter messages that contain repeated text. The rule will trigger if the message contains repeated text.
Example configuration for a Repeated Text Filter rule:
```json
{
"type": "repeated_text_filter",
"actions": [
{ "type": "warn", "reason": "Automatic: Posted repeated text" },
{ "type": "delete_message" },
]
}
```
**Options specific to Repeated Text Filter**
The maximum number of repeated characters allowed in the message.
The maximum number of repeated words allowed in the message.
### Mass Mention Filter
The Mass Mention Filter rule type is used to filter messages that contain mass mentions. The rule will trigger if the message contains mass mentions.
Example configuration for a Mass Mention Filter rule:
```json
{
"type": "mass_mention_filter",
"actions": [
{ "type": "warn", "reason": "Automatic: Posted mass mentions" },
{ "type": "delete_message" },
]
}
```
**Options specific to Mass Mention Filter**
The maximum number of mentions allowed in the message.
The maximum number of user mentions allowed in the message. `-1` means no limit.
The maximum number of role mentions allowed in the message. `-1` means no limit.
### Image Filter
The Image Filter rule type is used to filter messages that contain images. The rule will trigger if the message contains images that have text with specific words or tokens.
Example configuration for an Image Filter rule:
```json
{
"type": "image_filter",
"words": ["word1", "word2"],
"tokens": ["token1", "token2"],
"actions": [
{ "type": "warn", "reason": "Automatic: Posted an image with blocked text" },
{ "type": "delete_message" },
]
}
```
**Options specific to Image Filter**
string
}
>
An array of words to filter in the image.
string
}
>
An array of tokens to filter in the image.
Whether to inherit the words and tokens from the first Word Filter rule.
Whether to scan images inside embeds in the message.
### Embed Filter
The Embed Filter rule type is used to filter messages that contain embeds. The rule will trigger if the message contains embeds with specific words or tokens.
Example configuration for an Embed Filter rule:
```json
{
"type": "embed_filter",
"words": ["word1", "word2"],
"tokens": ["token1", "token2"],
"actions": [
{ "type": "warn", "reason": "Automatic: Posted an embed with blocked text" },
{ "type": "delete_message" },
]
}
```
**Options specific to Embed Filter**
string
}
>
An array of words to filter in the embeds.
string
}
>
An array of tokens to filter in the embeds.
Whether to inherit the words and tokens from the first Word Filter rule.
### Profile Filter
The Profile Filter rule type is used to filter user profiles based on specific conditions. The rule will trigger if the user profile contains specific words or tokens, or matches specific regular expressions.
Example configuration for a Profile Filter rule:
```json
{
"type": "profile_filter",
"words": ["word1", "word2"],
"tokens": ["token1", "token2"],
"regex_patterns": ["disc(o|0)rd\\.gg"],
"actions": [
{ "type": "warn", "reason": "Automatic: Profile contains blocked text" },
{ "type": "kick" },
]
}
```
**Options specific to Profile Filter**
string
}
>
An array of words to filter in the user profile.
string
}
>
An array of tokens to filter in the user profile.
string
}
>
An array of regular expressions to filter in the user profile.
Whether to normalize the words, tokens, and the user profile texts before filtering.
### AI Scan
The AI Scan rule type is used to scan messages using AI. The rule will trigger if the AI detects specific content in the message.
Example configuration for an AI Scan rule:
```json
{
"type": "ai_scan",
"actions": [
{ "type": "warn", "reason": "Automatic: Detected inappropriate content" },
{ "type": "delete_message" },
]
}
```
**Options specific to AI Scan**
The toxicity threshold for the AI scan. If the toxicity score of the message is greater than or equal to this threshold, the rule will trigger.
The identity attack threshold for the AI scan. If the identity attack score of the message is greater than or equal to this threshold, the rule will trigger.
The insult threshold for the AI scan. If the insult score of the message is greater than or equal to this threshold, the rule will trigger.
The profanity threshold for the AI scan. If the profanity score of the message is greater than or equal to this threshold, the rule will trigger.
The threat threshold for the AI scan. If the threat score of the message is greater than or equal to this threshold, the rule will trigger.
The sexually explicit threshold for the AI scan. If the sexually explicit score of the message is greater than or equal to this threshold, the rule will trigger.
The flirtation threshold for the AI scan. If the flirtation score of the message is greater than or equal to this threshold, the rule will trigger.
### File Filter
The File Filter rule type is used to filter messages that contain files. The rule will trigger if the message contains files with a blocked hash.
Example configuration for a File Filter rule:
```json
{
"type": "file_filter",
"hashes": { "d3d0bfbe67707d003ab937212ee96309b7f7beb6871391064917b70c20fa5a67": "image/png" },
"check_mime_types": false,
"actions": [
{ "type": "warn", "reason": "Automatic: Posted a file that is not allowed" },
{ "type": "delete_message" },
]
}
```
**Options specific to File Filter**
string,
string
]}>
Record
}
>
A record of file hashes to filter. The key is the hash and the value is the MIME type of the file. If the MIME type is `null`, the MIME type will not be checked.
Whether to check the MIME types of the files.
Documentation of the experimental rules might not be included here at this time. Please refer to the source code for more information.