Class AutoModRuleData
- All Implemented Interfaces:
SerializableData
AutoModRules
.
Every rule must configure at least one response
.
Example
TriggerConfig config = TriggerConfig.keywordFilter("discord.gg/*").addAllowList("gateway.discord.gg/*");
AutoModRuleData data = AutoModRuleData.onMessage("Invite Block", config);
data.addExemptRoles(guild.getRolesByName("Moderator", true));
data.putResponse(AutoModResponse.blockMessage());
- The
TriggerConfig
defines under what conditions the rule should be triggered and execute a response. It should trigger on all invite links, but not trigger on the gateway subdomain. - The rule is then created with this trigger config and we name it
"Invite Block"
. - Using
addExemptRoles(Role...)
, the moderator role has been excluded to allow moderators to post links. - With
putResponses(AutoModResponse...)
, an automatic action is enabled to block the message, whenever it triggers the rule.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddExemptChannels
(Collection<? extends GuildChannel> channels) Add channels which can bypass this rule.addExemptChannels
(GuildChannel... channels) Add channels which can bypass this rule.addExemptRoles
(Collection<? extends Role> roles) Add roles which can bypass this rule.addExemptRoles
(Role... roles) Add roles which can bypass this rule.Returns thePermissions
required to create this rule.static AutoModRuleData
onMemberProfile
(String name, TriggerConfig triggerConfig) Create a newAutoModRule
which triggers on a member profile being updated.static AutoModRuleData
onMessage
(String name, TriggerConfig triggerConfig) Create a newAutoModRule
which triggers on a message being sent in a channel.putResponses
(Collection<? extends AutoModResponse> responses) Configure what the rule should do upon triggering.putResponses
(AutoModResponse... responses) Configure what the rule should do upon triggering.setEnabled
(boolean enabled) Enable or disable the rule.setExemptChannels
(Collection<? extends GuildChannel> channels) Set which channels can bypass this rule.setExemptRoles
(Collection<? extends Role> roles) Set which roles can bypass this rule.Change the name of the rule.setResponses
(Collection<? extends AutoModResponse> responses) Configure what the rule should do upon triggering.setTriggerConfig
(TriggerConfig config) Change theTriggerConfig
for this rule.toData()
SerializedDataObject
for this object.
-
Method Details
-
onMessage
@Nonnull public static AutoModRuleData onMessage(@Nonnull String name, @Nonnull TriggerConfig triggerConfig) Create a newAutoModRule
which triggers on a message being sent in a channel.- Parameters:
name
- The name of the rule (1-100 characters)triggerConfig
- The trigger configuration for this rule- Returns:
- The new
AutoModRuleData
instance - Throws:
IllegalArgumentException
- If null is provided or the name is not between 1 and 100 characters
-
onMemberProfile
@Nonnull public static AutoModRuleData onMemberProfile(@Nonnull String name, @Nonnull TriggerConfig triggerConfig) Create a newAutoModRule
which triggers on a member profile being updated.- Parameters:
name
- The name of the rule (1-100 characters)triggerConfig
- The trigger configuration for this rule- Returns:
- The new
AutoModRuleData
instance - Throws:
IllegalArgumentException
- If null is provided or the name is not between 1 and 100 characters
-
setName
Change the name of the rule.- Parameters:
name
- The new name (1-100 characters)- Returns:
- The same
AutoModRuleData
instance - Throws:
IllegalArgumentException
- If the name is not between 1 and 100 characters
-
setEnabled
Enable or disable the rule.- Parameters:
enabled
- True, if the rule should be enabled- Returns:
- The same
AutoModRuleData
instance
-
putResponses
Configure what the rule should do upon triggering.
This is accumulative and adds ontop of the currently configured responses.Note that each response type can only be used once. If multiple responses of the same type are provided, the last one is used.
- Parameters:
responses
- The responses to configure- Returns:
- The same
AutoModRuleData
instance - Throws:
IllegalArgumentException
- If null is provided or any of the responses has anunknown type
-
putResponses
@Nonnull public AutoModRuleData putResponses(@Nonnull Collection<? extends AutoModResponse> responses) Configure what the rule should do upon triggering.
This is accumulative and adds ontop of the currently configured responses.Note that each response type can only be used once. If multiple responses of the same type are provided, the last one is used.
- Parameters:
responses
- The responses to configure- Returns:
- The same
AutoModRuleData
instance - Throws:
IllegalArgumentException
- If null is provided or any of the responses has anunknown type
-
setResponses
@Nonnull public AutoModRuleData setResponses(@Nonnull Collection<? extends AutoModResponse> responses) Configure what the rule should do upon triggering.
This replaces the currently configured responses, removing all previously configured responses.Note that each response type can only be used once. If multiple responses of the same type are provided, the last one is used.
- Parameters:
responses
- The responses to configure- Returns:
- The same
AutoModRuleData
instance - Throws:
IllegalArgumentException
- If null is provided or any of the responses has anunknown type
-
addExemptRoles
Add roles which can bypass this rule.Roles added to the exemptions will allow all of its members to bypass this rule.
- Parameters:
roles
- The roles to add (up to 20 roles)- Returns:
- The same
AutoModRuleData
instance - Throws:
IllegalArgumentException
- If null is provided or the number of roles exceeds 20
-
addExemptRoles
Add roles which can bypass this rule.Roles added to the exemptions will allow all of its members to bypass this rule.
- Parameters:
roles
- The roles to add (up to 20 roles)- Returns:
- The same
AutoModRuleData
instance - Throws:
IllegalArgumentException
- If null is provided or the number of roles exceeds 20
-
setExemptRoles
Set which roles can bypass this rule.Roles added to the exemptions will allow all of its members to bypass this rule.
- Parameters:
roles
- The roles to exempt (up to 20 roles)- Returns:
- The same
AutoModRuleData
instance - Throws:
IllegalArgumentException
- If null is provided or the number of roles exceeds 20
-
addExemptChannels
Add channels which can bypass this rule.No messages sent in this channel will trigger the rule.
- Parameters:
channels
- The channels to add (up to 50 channels)- Returns:
- The same
AutoModRuleData
instance - Throws:
IllegalArgumentException
- If null is provided or the number of channels exceeds 50
-
addExemptChannels
@Nonnull public AutoModRuleData addExemptChannels(@Nonnull Collection<? extends GuildChannel> channels) Add channels which can bypass this rule.No messages sent in this channel will trigger the rule.
- Parameters:
channels
- The channels to add (up to 50 channels)- Returns:
- The same
AutoModRuleData
instance - Throws:
IllegalArgumentException
- If null is provided or the number of channels exceeds 50
-
setExemptChannels
@Nonnull public AutoModRuleData setExemptChannels(@Nonnull Collection<? extends GuildChannel> channels) Set which channels can bypass this rule.No messages sent in this channel will trigger the rule.
- Parameters:
channels
- The channels to add (up to 50 channels)- Returns:
- The same
AutoModRuleData
instance - Throws:
IllegalArgumentException
- If null is provided or the number of channels exceeds 50
-
setTriggerConfig
Change theTriggerConfig
for this rule.- Parameters:
config
- The new config- Returns:
- The same
AutoModRuleData
instance - Throws:
IllegalArgumentException
- If null is provided
-
getRequiredPermissions
Returns thePermissions
required to create this rule.
CertainTypes
require additional permissions, such asAutoModResponse.Type.TIMEOUT
. All rules requirePermission.MANAGE_SERVER
to be created.- Returns:
- The required permissions to create this rule
-
toData
Description copied from interface:SerializableData
SerializedDataObject
for this object.- Specified by:
toData
in interfaceSerializableData
- Returns:
DataObject
-