Class AllowedMentions

  • All Implemented Interfaces:
    org.json.JSONString

    public class AllowedMentions
    extends Object
    implements org.json.JSONString
    Constructs a whitelist of allowed mentions for a message. If any argument in this class is null, a NullPointerException will be thrown.

    Example

    
     AllowedMentions mentions = new AllowedMentions()
       .withUsers("86699011792191488", "107562988810027008")
       .withParseEveryone(false)
       .withParseRoles(false);
    
     // This will only mention the user with the id 86699011792191488 (Minn#6688)
     // The @everyone will be ignored since the allowed mentions disabled it.
     client.send(
       new WebhookMessageBuilder()
         .setAllowedMentions(mentions)
         .setContent("Hello <@86699011792191488>! And hello @everyone else!")
         .build()
     );
     
    See Also:
    WebhookMessageBuilder.setAllowedMentions(AllowedMentions), WebhookClientBuilder#setAllowedMentions(AllowedMentions), all(), none()
    • Constructor Detail

      • AllowedMentions

        public AllowedMentions()
    • Method Detail

      • all

        public static AllowedMentions all()
        Parse all mentions.

        Equivalent:

        
         return new AllowedMentions()
             .withParseEveryone(true)
             .withParseRoles(true)
             .withParseUsers(true);
         
        Returns:
        Every mention type will be parsed.
      • none

        public static AllowedMentions none()
        Disable all mentions.

        Equivalent:

        
         return new AllowedMentions()
             .withParseEveryone(false)
             .withParseRoles(false)
             .withParseUsers(false);
         
        Returns:
        No mentions will be parsed.
      • withUsers

        @NotNull
        public @NotNull AllowedMentions withUsers​(@NotNull
                                                  @NotNull String... userId)
        Whitelist specified users for mention.
        This will set withParseUsers(boolean) to false.
        Parameters:
        userId - The whitelist of users to mention
        Returns:
        AllowedMentions instance with applied whitelist
      • withRoles

        @NotNull
        public @NotNull AllowedMentions withRoles​(@NotNull
                                                  @NotNull String... roleId)
        Whitelist specified roles for mention.
        This will set withParseRoles(boolean) to false.
        Parameters:
        roleId - The whitelist of roles to mention
        Returns:
        AllowedMentions instance with applied whitelist
      • withUsers

        @NotNull
        public @NotNull AllowedMentions withUsers​(@NotNull
                                                  @NotNull Collection<String> userId)
        Whitelist specified users for mention.
        This will set withParseUsers(boolean) to false.
        Parameters:
        userId - The whitelist of users to mention
        Returns:
        AllowedMentions instance with applied whitelist
      • withRoles

        @NotNull
        public @NotNull AllowedMentions withRoles​(@NotNull
                                                  @NotNull Collection<String> roleId)
        Whitelist specified roles for mention.
        This will set withParseRoles(boolean) to false.
        Parameters:
        roleId - The whitelist of roles to mention
        Returns:
        AllowedMentions instance with applied whitelist
      • withParseEveryone

        @NotNull
        public @NotNull AllowedMentions withParseEveryone​(boolean allowEveryoneMention)
        Whether to parse @everyone or @here mentions.
        Parameters:
        allowEveryoneMention - True, if @everyone should be parsed
        Returns:
        AllowedMentions instance with applied parsing rule
      • withParseUsers

        @NotNull
        public @NotNull AllowedMentions withParseUsers​(boolean allowParseUsers)
        Whether to parse user mentions.
        Setting this to true will clear the whitelist provided by withUsers(String...).
        Parameters:
        allowParseUsers - True, if all user mentions should be parsed
        Returns:
        AllowedMentions instance with applied parsing rule
      • withParseRoles

        @NotNull
        public @NotNull AllowedMentions withParseRoles​(boolean allowParseRoles)
        Whether to parse role mentions.
        Setting this to true will clear the whitelist provided by withRoles(String...).
        Parameters:
        allowParseRoles - True, if all role mentions should be parsed
        Returns:
        AllowedMentions instance with applied parsing rule
      • toJSONString

        public String toJSONString()
        Specified by:
        toJSONString in interface org.json.JSONString