Class AllowedMentions
- java.lang.Object
-
- club.minnced.discord.webhook.send.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 isnull, aNullPointerExceptionwill 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() );
-
-
Constructor Summary
Constructors Constructor Description AllowedMentions()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AllowedMentionsall()Parse all mentions.static AllowedMentionsnone()Disable all mentions.StringtoJSONString()@NotNull AllowedMentionswithParseEveryone(boolean allowEveryoneMention)Whether to parse@everyoneor@herementions.@NotNull AllowedMentionswithParseRoles(boolean allowParseRoles)Whether to parse role mentions.@NotNull AllowedMentionswithParseUsers(boolean allowParseUsers)Whether to parse user mentions.@NotNull AllowedMentionswithRoles(@NotNull String... roleId)Whitelist specified roles for mention.@NotNull AllowedMentionswithRoles(@NotNull Collection<String> roleId)Whitelist specified roles for mention.@NotNull AllowedMentionswithUsers(@NotNull String... userId)Whitelist specified users for mention.@NotNull AllowedMentionswithUsers(@NotNull Collection<String> userId)Whitelist specified users for mention.
-
-
-
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 setwithParseUsers(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 setwithParseRoles(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 setwithParseUsers(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 setwithParseRoles(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@everyoneor@herementions.- Parameters:
allowEveryoneMention- True, if@everyoneshould be parsed- Returns:
- AllowedMentions instance with applied parsing rule
-
withParseUsers
@NotNull public @NotNull AllowedMentions withParseUsers(boolean allowParseUsers)
Whether to parse user mentions.
Setting this totruewill clear the whitelist provided bywithUsers(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 totruewill clear the whitelist provided bywithRoles(String...).- Parameters:
allowParseRoles- True, if all role mentions should be parsed- Returns:
- AllowedMentions instance with applied parsing rule
-
toJSONString
public String toJSONString()
- Specified by:
toJSONStringin interfaceorg.json.JSONString
-
-