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 StringavatarId(@NotNull net.dv8tion.jda.api.entities.User user) Gets the ID hash of the user's custom avatar.static @Nullable StringavatarLink(@NotNull net.dv8tion.jda.api.entities.User user) Gets the URL of the user's custom avatar.static @NotNull net.dv8tion.jda.api.requests.RestAction<@Nullable String> bannerId(@NotNull net.dv8tion.jda.api.entities.User user) Retrieves the ID hash of the user's profile banner.static @NotNull net.dv8tion.jda.api.requests.RestAction<@Nullable String> bannerLink(@NotNull net.dv8tion.jda.api.entities.User user) Retrieves the URL of the user's profile banner.static @NotNull OffsetDateTimecreatedTime(@NotNull net.dv8tion.jda.api.entities.User user) Gets the exact time the user's Discord account was created.static @NotNull StringdebugTag(@NotNull net.dv8tion.jda.api.entities.User user) Gets a formatted string useful for logging or debugging, combining the user's display name and ID.static @NotNull StringdefaultAvatarId(@NotNull net.dv8tion.jda.api.entities.User user) Gets the identifier for the user's default Discord avatar.static @NotNull StringdefaultAvatarLink(@NotNull net.dv8tion.jda.api.entities.User user) Gets the URL of the user's default Discord avatar.static @NotNull StringdisplayName(@NotNull net.dv8tion.jda.api.entities.User user) Gets the effective display name of the user.static @NotNull StringeffectiveAvatarLink(@NotNull net.dv8tion.jda.api.entities.User user) Gets the effective avatar URL for the user.static @Nullable net.dv8tion.jda.api.entities.UsergetCachedUser(@NotNull String id) Retrieves a user by their ID directly from the internal JDA cache.static @Nullable StringglobalName(@NotNull net.dv8tion.jda.api.entities.User user) Gets the global display name of the user, if they have set one.static booleanhasGlobalName(@NotNull net.dv8tion.jda.api.entities.User user) Checks if the user has configured a global display name.static booleanhasPrivateChannel(@NotNull net.dv8tion.jda.api.entities.User user) Checks if the bot currently has an open Private Channel (DM) with this user.static @NotNull Stringid(@NotNull net.dv8tion.jda.api.entities.User user) Gets the snowflake ID of the user.static voidinitialize(@NotNull net.dv8tion.jda.api.JDA jda) Initializes the UserUtils with a JDA instance.static @NotNull Stringmention(@NotNull net.dv8tion.jda.api.entities.User user) Gets the mention string for the specified user.static @NotNull net.dv8tion.jda.api.requests.RestAction<net.dv8tion.jda.api.entities.User> retrieveUser(@NotNull String id) Retrieves a user by their ID from the Discord API.static @NotNull Stringtag(@NotNull net.dv8tion.jda.api.entities.User user) Deprecated.Discord has removed discriminators.static @NotNull Stringusername(@NotNull net.dv8tion.jda.api.entities.User user) Gets the raw username of the user.
-
Method Details
-
initialize
public static void initialize(@NotNull @NotNull net.dv8tion.jda.api.JDA jda) 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
@NotNull public static @NotNull String mention(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) 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
@NotNull public static @NotNull String username(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) Gets the raw username of the user.- Parameters:
user- The target user.- Returns:
- The user's account username.
-
globalName
@Nullable public static @Nullable String globalName(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) 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
@NotNull public static @NotNull String displayName(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) 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
public static boolean hasGlobalName(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) Checks if the user has configured a global display name.- Parameters:
user- The target user.- Returns:
trueif a global name is set,falseotherwise.
-
tag
@NotNull @Deprecated public static @NotNull String tag(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) 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
@NotNull public static @NotNull String debugTag(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) 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
@Nullable public static @Nullable String avatarLink(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) 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
@Nullable public static @Nullable String avatarId(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) 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
@NotNull public static @NotNull String effectiveAvatarLink(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) 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
@NotNull public static @NotNull String defaultAvatarLink(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) Gets the URL of the user's default Discord avatar.- Parameters:
user- The target user.- Returns:
- The default avatar URL.
-
defaultAvatarId
@NotNull public static @NotNull String defaultAvatarId(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) Gets the identifier for the user's default Discord avatar.- Parameters:
user- The target user.- Returns:
- The default avatar ID.
-
hasPrivateChannel
public static boolean hasPrivateChannel(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) 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 net.dv8tion.jda.api.requests.RestAction<@Nullable String> bannerLink(@NotNull @NotNull net.dv8tion.jda.api.entities.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
@NotNull public static @NotNull net.dv8tion.jda.api.requests.RestAction<@Nullable String> bannerId(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) 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
@NotNull public static @NotNull net.dv8tion.jda.api.requests.RestAction<net.dv8tion.jda.api.entities.User> retrieveUser(@NotNull @NotNull String id) 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
@Nullable public static @Nullable net.dv8tion.jda.api.entities.User getCachedUser(@NotNull @NotNull String id) 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
@NotNull public static @NotNull OffsetDateTime createdTime(@NotNull @NotNull net.dv8tion.jda.api.entities.User user) Gets the exact time the user's Discord account was created.- Parameters:
user- The target user.- Returns:
- An
OffsetDateTimerepresenting the account creation timestamp.
-