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:

{
    // 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:

rule.type:
|"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.

rule.name?:
string

The name of the rule. This is optional and is used for identification purposes.

Optional
rule.enabled?:
boolean

Whether the rule is enabled or not. If this is set to false, the rule will be ignored.

Default: true
Optional
rule.mode?:
"normal"|"inverse"

The mode of the rule. If set to inverse, the rule will be triggered when the trigger condition is not met.

Default: "normal"
Optional
rule.bail?:
boolean

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.

Default: true
Optional
rule.actions:
ModerationAction[]

An array of actions to perform when the rule is triggered. Each action is a ModerationAction object.

rule.for?:
MessageRuleCondition

The condition that must be met for the rule to be triggered. This is an object that defines the condition.

Optional
rule.exceptions?:
MessageRuleCondition

The condition that must be met for the rule to be ignored. This is an object that defines the condition.

Optional
rule.is_bypasser?:
boolean

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.

Default: false
Optional
rule.bypasses:
string[]|null

An array of rule names that this rule bypasses. This option is only used when is_bypasser is set to true.

Default: null

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.

Info

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:

{
    "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

rule.words?:
string[]

An array of words to filter.

Optional
rule.tokens?:
string[]

An array of tokens to filter.

Optional
rule.normalize:
boolean

Whether to normalize the words, tokens, and the message before filtering.

Default: true

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:

{
    "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

rule.patterns:
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:

{
    "type": "anti_invite",
    "actions": [
        { "type": "warn", "reason": "Automatic: Posted a Discord invite link" },
        { "type": "delete_message" },
    ]
}

Options specific to Anti-Invite

rule.allowed_invite_codes:
string[]

An array of invite codes that are allowed.

Default: []
rule.allow_internal_invites:
boolean

Whether to allow internal server invites.

Default: true

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:

{
    "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

rule.domains:
string[]

An array of domains to filter.

rule.scan_links_only:
boolean

Whether to scan only the links in the message.

Default: false

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:

{
    "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

rule.data:
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:

{
    "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

rule.data:
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:

{
    "type": "repeated_text_filter",
    "actions": [
        { "type": "warn", "reason": "Automatic: Posted repeated text" },
        { "type": "delete_message" },
    ]
}

Options specific to Repeated Text Filter

rule.max_repeated_chars:
number

The maximum number of repeated characters allowed in the message.

Default: 20
rule.max_repeated_words:
number

The maximum number of repeated words allowed in the message.

Default: 15

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:

{
    "type": "mass_mention_filter",
    "actions": [
        { "type": "warn", "reason": "Automatic: Posted mass mentions" },
        { "type": "delete_message" },
    ]
}

Options specific to Mass Mention Filter

rule.max_mentions:
number

The maximum number of mentions allowed in the message.

Default: 15
rule.max_user_mentions:
number

The maximum number of user mentions allowed in the message. -1 means no limit.

Default: -1
rule.max_role_mentions:
number

The maximum number of role mentions allowed in the message. -1 means no limit.

Default: -1

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:

{
    "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

rule.words?:
string[]

An array of words to filter in the image.

Optional
rule.tokens?:
string[]

An array of tokens to filter in the image.

Optional
rule.inherit_from_word_filter:
boolean

Whether to inherit the words and tokens from the first Word Filter rule.

Default: false
rule.scan_embeds:
boolean

Whether to scan images inside embeds in the message.

Default: false

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:

{
    "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

rule.words?:
string[]

An array of words to filter in the embeds.

Optional
rule.tokens?:
string[]

An array of tokens to filter in the embeds.

Optional
rule.inherit_from_word_filter:
boolean

Whether to inherit the words and tokens from the first Word Filter rule.

Default: false

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:

{
    "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

rule.words?:
string[]

An array of words to filter in the user profile.

Optional
rule.tokens?:
string[]

An array of tokens to filter in the user profile.

Optional
rule.regex_patterns?:
string[]

An array of regular expressions to filter in the user profile.

Optional
rule.normalize:
boolean

Whether to normalize the words, tokens, and the user profile texts before filtering.

Default: true

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:

{
    "type": "ai_scan",
    "actions": [
        { "type": "warn", "reason": "Automatic: Detected inappropriate content" },
        { "type": "delete_message" },
    ]
}

Options specific to AI Scan

rule.toxicity_threshold:
number

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.

Default: 0.5
rule.identity_attack_threshold:
number

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.

Default: 0.5
rule.insult_threshold:
number

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.

Default: 0.5
rule.profanity_threshold:
number

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.

Default: 0.5
rule.threat_threshold:
number

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.

Default: 0.5
rule.sexually_explicit_threshold:
number

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.

Default: 0.5
rule.flirtation_threshold:
number

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.

Default: 0.5

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:

{
    "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

rule.hashes:
Record<string,string|null>

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.

rule.check_mime_types:
boolean

Whether to check the MIME types of the files.

Default: false
Info

Documentation of the experimental rules might not be included here at this time. Please refer to the source code for more information.