Package com.dianxin.tori.api.utils.jda
Class UserUtils
java.lang.Object
com.dianxin.tori.api.utils.jda.UserUtils
A utility class providing convenient methods to extract information from and interact
with JDA
User objects.
Note: Methods that retrieve users from the API or cache require this class
to be initialized via initialize(JDA) first.
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable StringGets the ID hash of the user's custom avatar.static @Nullable StringavatarLink(@NotNull User user) Gets the URL of the user's custom avatar.static @NotNull RestAction<@Nullable String> Retrieves the ID hash of the user's profile banner.static @NotNull RestAction<@Nullable String> bannerLink(@NotNull User user) Retrieves the URL of the user's profile banner.static @NotNull OffsetDateTimecreatedTime(@NotNull User user) Gets the exact time the user's Discord account was created.static @NotNull StringGets a formatted string useful for logging or debugging, combining the user's display name and ID.static @NotNull StringdefaultAvatarId(@NotNull User user) Gets the identifier for the user's default Discord avatar.static @NotNull StringdefaultAvatarLink(@NotNull User user) Gets the URL of the user's default Discord avatar.static @NotNull StringdisplayName(@NotNull User user) Gets the effective display name of the user.static @NotNull StringeffectiveAvatarLink(@NotNull User user) Gets the effective avatar URL for the user.static @Nullable UsergetCachedUser(@NotNull String id) Retrieves a user by their ID directly from the internal JDA cache.static @Nullable StringglobalName(@NotNull User user) Gets the global display name of the user, if they have set one.static booleanhasGlobalName(@NotNull User user) Checks if the user has configured a global display name.static booleanhasPrivateChannel(@NotNull User user) Checks if the bot currently has an open Private Channel (DM) with this user.static @NotNull StringGets the snowflake ID of the user.static voidinitialize(@NotNull JDA jda) Initializes the UserUtils with a JDA instance.static @NotNull StringGets the mention string for the specified user.static @NotNull RestAction<User> retrieveUser(@NotNull String id) Retrieves a user by their ID from the Discord API.static @NotNull StringDeprecated.Discord has removed discriminators.static @NotNull StringGets the raw username of the user.
-
Method Details
-
initialize
Initializes the UserUtils with a JDA instance. This must be called before usingretrieveUser(String)orgetCachedUser(String).- Parameters:
jda- The JDA instance to be used for user lookups.
-
mention
Gets the mention string for the specified user.- Parameters:
user- The user to mention.- Returns:
- The mention string (e.g.,
<@123456789>).
-
id
Gets the snowflake ID of the user.- Parameters:
user- The target user.- Returns:
- The user's ID as a String.
-
username
Gets the raw username of the user.- Parameters:
user- The target user.- Returns:
- The user's account username.
-
globalName
Gets the global display name of the user, if they have set one.- Parameters:
user- The target user.- Returns:
- The global name, or
nullif not set.
-
displayName
Gets the effective display name of the user. Returns the global name if present; otherwise, falls back to their standard username.- Parameters:
user- The target user.- Returns:
- The effective display name.
-
hasGlobalName
Checks if the user has configured a global display name.- Parameters:
user- The target user.- Returns:
trueif a global name is set,falseotherwise.
-
tag
Deprecated.Discord has removed discriminators. Useusername(User)ordisplayName(User)instead.Gets the user's tag (Username#Discriminator).- Parameters:
user- The target user.- Returns:
- The user's tag.
-
debugTag
Gets a formatted string useful for logging or debugging, combining the user's display name and ID.- Parameters:
user- The target user.- Returns:
- A string formatted as "DisplayName (ID)".
-
avatarLink
Gets the URL of the user's custom avatar.- Parameters:
user- The target user.- Returns:
- The avatar URL, or
nullif they are using a default avatar.
-
avatarId
Gets the ID hash of the user's custom avatar.- Parameters:
user- The target user.- Returns:
- The avatar ID, or
nullif they are using a default avatar.
-
effectiveAvatarLink
Gets the effective avatar URL for the user. This will return their custom avatar if present, or their default avatar otherwise.- Parameters:
user- The target user.- Returns:
- The effective avatar URL.
-
defaultAvatarLink
Gets the URL of the user's default Discord avatar.- Parameters:
user- The target user.- Returns:
- The default avatar URL.
-
defaultAvatarId
Gets the identifier for the user's default Discord avatar.- Parameters:
user- The target user.- Returns:
- The default avatar ID.
-
hasPrivateChannel
Checks if the bot currently has an open Private Channel (DM) with this user.- Parameters:
user- The target user.- Returns:
trueif a private channel exists in cache.
-
bannerLink
@NotNull public static @NotNull RestAction<@Nullable String> bannerLink(@NotNull @NotNull User user) Retrieves the URL of the user's profile banner. This operation requires an API request.- Parameters:
user- The target user.- Returns:
- A
RestActionresolving to the banner URL, ornullif no banner is set.
-
bannerId
Retrieves the ID hash of the user's profile banner. This operation requires an API request.- Parameters:
user- The target user.- Returns:
- A
RestActionresolving to the banner ID, ornullif no banner is set.
-
retrieveUser
Retrieves a user by their ID from the Discord API.Requires
initialize(JDA)to have been called previously.- Parameters:
id- The snowflake ID of the user.- Returns:
- A
RestActionresolving to the requestedUser.
-
getCachedUser
Retrieves a user by their ID directly from the internal JDA cache.Requires
initialize(JDA)to have been called previously.- Parameters:
id- The snowflake ID of the user.- Returns:
- The cached
User, ornullif the user is not in the cache.
-
createdTime
Gets the exact time the user's Discord account was created.- Parameters:
user- The target user.- Returns:
- An
OffsetDateTimerepresenting the account creation timestamp.
-