AutoMod
AutoMod is a system implemented by Discord, helping administrators to moderate their servers, by filtering messages, status, names and more.
How it works?
A message, member's name or status will trigger an automod rule, and then take the desired actions to counter it. Multiple rules can be triggered at the same time, and multiple actions can be taken for the same rule.
Triggers
- Message Received (Triggered when the message contains a specific word/regex pattern)
Note
Currently (as of 12/06/2023), JDA only supports message trigger. Other triggers will be added in the near future.
Different Filter's Type
You can use different filters to trigger the message received rule:
- Keyword: The message contains the specified words
- Pattern: The message matches the specified regex pattern
- Mention: The message contains more than the specified amount of mentions
Actions
- Block the message (with an optional reason)
- Send an alert in a channel
- Timeout the member for a specific duration
Script Code
Creating a Rule
Now we've seen how it works, let's see how to implement it in a script. First, we need to create a new automod rule, to then create the rule in a guild:
- This will create a new automod rule, and store it in the local variable
rule
. It can then be used outside the section.
Changing the Rule's Trigger
We'll put all of our code related to automod rule creation inside this section. Let's now see how to change its trigger:
create a new automod rule and store it in {_rule}:
set type of rule to (message with keyword filter "morb" named "no morb rule")
Will be triggered if a message contains the word morb
Adding Actions
We can now add actions/responses to our rule:
create a new automod rule and store it in {_rule}:
set type of rule to ...
add block message to responses of rule #(1)!
-
You can also specific a reason such as:
Will make the AutoModeration bot delete the message, with the optionally specified reason. It'll look like this:
Creating the Rule in a Guild
Now that we've created our rule, we can create it in a guild:
create a new automod rule and store it in {_rule}:
set type of rule to ...
add ... to responses of rule
create rule {_rule} in guild with id "000" # or any other guild
And here you go ✨, you've created your first automod rule!