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
, aNullPointerException
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() );
-
-
Constructor Summary
Constructors Constructor Description AllowedMentions()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AllowedMentions
all()
Parse all mentions.static AllowedMentions
none()
Disable all mentions.String
toJSONString()
@NotNull AllowedMentions
withParseEveryone(boolean allowEveryoneMention)
Whether to parse@everyone
or@here
mentions.@NotNull AllowedMentions
withParseRoles(boolean allowParseRoles)
Whether to parse role mentions.@NotNull AllowedMentions
withParseUsers(boolean allowParseUsers)
Whether to parse user mentions.@NotNull AllowedMentions
withRoles(@NotNull String... roleId)
Whitelist specified roles for mention.@NotNull AllowedMentions
withRoles(@NotNull Collection<String> roleId)
Whitelist specified roles for mention.@NotNull AllowedMentions
withUsers(@NotNull String... userId)
Whitelist specified users for mention.@NotNull AllowedMentions
withUsers(@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@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 totrue
will 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 totrue
will 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:
toJSONString
in interfaceorg.json.JSONString
-
-