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:
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.
rule.enabled
?:
boolean
Whether the rule is enabled or not. If this is set to false
, the rule will
be ignored.
true
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.
"normal"
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.
true
rule.actions
:
An array of actions to perform when the rule is triggered. Each action is a
ModerationAction
object.
rule.for
?:
The condition that must be met for the rule to be triggered. This is an object that defines the condition.
rule.exceptions
?:
The condition that must be met for the rule to be ignored. This is an object that defines the condition.
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.
false
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
.
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.
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:
Options specific to Word Filter
rule.words
?:
string[]
An array of words to filter.
rule.tokens
?:
string[]
An array of tokens to filter.
rule.normalize
:
boolean
Whether to normalize the words, tokens, and the message before filtering.
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:
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:
Options specific to Anti-Invite
rule.allowed_invite_codes
:
string[]
An array of invite codes that are allowed.
[]
rule.allow_internal_invites
:
boolean
Whether to allow internal server invites.
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:
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.
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:
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:
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:
Options specific to Repeated Text Filter
rule.max_repeated_chars
:
number
The maximum number of repeated characters allowed in the message.
20
rule.max_repeated_words
:
number
The maximum number of repeated words allowed in the message.
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:
Options specific to Mass Mention Filter
rule.max_mentions
:
number
The maximum number of mentions allowed in the message.
15
rule.max_user_mentions
:
number
The maximum number of user mentions allowed in the message. -1
means no limit.
-1
rule.max_role_mentions
:
number
The maximum number of role mentions allowed in the message. -1
means no limit.
-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:
Options specific to Image Filter
rule.words
?:
string[]
An array of words to filter in the image.
rule.tokens
?:
string[]
An array of tokens to filter in the image.
rule.inherit_from_word_filter
:
boolean
Whether to inherit the words and tokens from the first Word Filter rule.
false
rule.scan_embeds
:
boolean
Whether to scan images inside embeds in the message.
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:
Options specific to Embed Filter
rule.words
?:
string[]
An array of words to filter in the embeds.
rule.tokens
?:
string[]
An array of tokens to filter in the embeds.
rule.inherit_from_word_filter
:
boolean
Whether to inherit the words and tokens from the first Word Filter rule.
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:
Options specific to Profile Filter
rule.words
?:
string[]
An array of words to filter in the user profile.
rule.tokens
?:
string[]
An array of tokens to filter in the user profile.
rule.regex_patterns
?:
string[]
An array of regular expressions to filter in the user profile.
rule.normalize
:
boolean
Whether to normalize the words, tokens, and the user profile texts before filtering.
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:
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.
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.
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.
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.
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.
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.
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.
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:
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.
false
Documentation of the experimental rules might not be included here at this time. Please refer to the source code for more information.