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.
- Message Received (Triggered when the message contains a specific word/regex pattern)
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
- Block the message (with an optional reason)
- Send an alert in a channel
- Timeout the member for a specific duration
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:
Will be triggered if a message contains the word
Will be triggered if a message matches the regex pattern
We can now add actions/responses to our rule:
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:
Will make the AutoModeration bot send an alert in the specified channel. 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:
And here you go ✨, you've created your first automod rule!