Class AutoModRuleData

java.lang.Object
net.dv8tion.jda.api.entities.automod.build.AutoModRuleData
All Implemented Interfaces:
SerializableData

public class AutoModRuleData extends Object implements SerializableData
Data class used to create new 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());
  1. 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.
  2. The rule is then created with this trigger config and we name it "Invite Block".
  3. Using addExemptRoles(Role...), the moderator role has been excluded to allow moderators to post links.
  4. With putResponses(AutoModResponse...), an automatic action is enabled to block the message, whenever it triggers the rule.
See Also:
  • Method Details

    • onMessage

      @Nonnull public static AutoModRuleData onMessage(@Nonnull String name, @Nonnull TriggerConfig triggerConfig)
      Create a new AutoModRule 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 new AutoModRule 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

      @Nonnull public AutoModRuleData setName(@Nonnull String name)
      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

      @Nonnull public AutoModRuleData setEnabled(boolean enabled)
      Enable or disable the rule.
      Parameters:
      enabled - True, if the rule should be enabled
      Returns:
      The same AutoModRuleData instance
    • putResponses

      @Nonnull public AutoModRuleData putResponses(@Nonnull 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 an unknown 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 an unknown 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 an unknown type
    • addExemptRoles

      @Nonnull public AutoModRuleData addExemptRoles(@Nonnull Role... roles)
      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

      @Nonnull public AutoModRuleData addExemptRoles(@Nonnull Collection<? extends Role> roles)
      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

      @Nonnull public AutoModRuleData setExemptRoles(@Nonnull Collection<? extends Role> roles)
      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

      @Nonnull public AutoModRuleData addExemptChannels(@Nonnull 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
    • 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

      @Nonnull public AutoModRuleData setTriggerConfig(@Nonnull TriggerConfig config)
      Change the TriggerConfig for this rule.
      Parameters:
      config - The new config
      Returns:
      The same AutoModRuleData instance
      Throws:
      IllegalArgumentException - If null is provided
    • getRequiredPermissions

      @Nonnull public EnumSet<Permission> getRequiredPermissions()
      Returns the Permissions required to create this rule.
      Certain Types require additional permissions, such as AutoModResponse.Type.TIMEOUT. All rules require Permission.MANAGE_SERVER to be created.
      Returns:
      The required permissions to create this rule
    • toData

      @Nonnull public DataObject toData()
      Description copied from interface: SerializableData
      Serialized DataObject for this object.
      Specified by:
      toData in interface SerializableData
      Returns:
      DataObject