Package net.dv8tion.jda.api.entities
Interface User
- All Superinterfaces:
- Formattable,- IMentionable,- ISnowflake,- UserSnowflake
- All Known Subinterfaces:
- SelfUser
Represents a Discord User.
 Contains all publicly available information about a specific Discord User.
 
Formattable
 This interface extends Formattable and can be used with a Formatter
 such as used by String.format(String, Object...)
 or PrintStream.printf(String, Object...).
 
This will use IMentionable.getAsMention() rather than Object.toString()!
 
Supported Features:
 
- Alternative
     
 - Uses the Discord Tag (Username#Discriminator) instead (Example:%#s- results ingetName()#getDiscriminator()-> Minn#6688
- Width/Left-Justification
     
 - Ensures the size of a format (Example:%20s- uses at minimum 20 chars;%-10s- uses left-justified padding)
- Precision
     
 - Cuts the content to the specified size (Example:%.20s)
More information on formatting syntax can be found in the format syntax documentation!
- 
Nested Class SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic classRepresents the information contained in aUser's profile.static enumRepresents the bit offsets used by Discord for public flags
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringTemplate forgetAvatarUrl().static final StringTemplate forUser.Profile.getBannerUrl()static final intUsed to keep consistency between color values used in the APIstatic final StringTemplate forUserSnowflake.getDefaultAvatarUrl()static final PatternCompiled pattern for a Discord Tag:(.{2,32})#(\d{4})
- 
Method SummaryModifier and TypeMethodDescriptionstatic UserSnowflakefromId(long id) Creates a User instance which only wraps an ID.static UserSnowflakeCreates a User instance which only wraps an ID.getAsTag()The "tag" for this userdefault ImageProxyReturns anImageProxyfor this user's avatar.The Discord ID for this user's avatar image.default StringThe URL for the user's avatar image.The discriminator of theUser.default ImageProxyReturns anImageProxyfor this user's effective avatar image.default StringThe URL for the user's avatar image.default StringThe name visible in the UI.getFlags()Returns theUserFlagsof this user.intReturns the bitmask representation of theUserFlagsof this user.The global display name of the user.getJDA()Returns theJDAinstance of this UsergetName()The username of theUser.booleanWhether or not the currently logged in user and this user have a currently openPrivateChannelor not.booleanisBot()Returns whether or not the given user is a Bot-Account (special badge in client, some different behaviour)booleanisSystem()Returns whether or not the given user is a System account, which includes the urgent message account and the community updates bot.Opens aPrivateChannelwith this User.Loads the user'sUser.Profiledata.Methods inherited from interface net.dv8tion.jda.api.entities.IMentionableformatTo, getAsMentionMethods inherited from interface net.dv8tion.jda.api.entities.ISnowflakegetId, getIdLong, getTimeCreatedMethods inherited from interface net.dv8tion.jda.api.entities.UserSnowflakegetDefaultAvatar, getDefaultAvatarId, getDefaultAvatarUrl
- 
Field Details- 
USER_TAGCompiled pattern for a Discord Tag:(.{2,32})#(\d{4})
- 
AVATAR_URLTemplate forgetAvatarUrl().- See Also:
 
- 
DEFAULT_AVATAR_URLTemplate forUserSnowflake.getDefaultAvatarUrl()- See Also:
 
- 
BANNER_URLTemplate forUser.Profile.getBannerUrl()- See Also:
 
- 
DEFAULT_ACCENT_COLOR_RAWstatic final int DEFAULT_ACCENT_COLOR_RAWUsed to keep consistency between color values used in the API- See Also:
 
 
- 
- 
Method Details- 
fromIdCreates a User instance which only wraps an ID.- Parameters:
- id- The user id
- Returns:
- A UserSnowflakeinstance
- See Also:
 
- 
fromIdCreates a User instance which only wraps an ID.- Parameters:
- id- The user id
- Returns:
- A UserSnowflakeinstance
- Throws:
- IllegalArgumentException- If the provided ID is not a valid snowflake
- See Also:
 
- 
getNameThe username of theUser. Length is between 2 and 32 characters (inclusive).- Returns:
- Never-null String containing the User's username.
 
- 
getGlobalNameThe global display name of the user.
 This name is not unique and allows more characters.This name is usually displayed in the UI. - Returns:
- The global display name or null if unset.
 
- 
getEffectiveName- Returns:
- The effective display name
 
- 
getDiscriminatorThe discriminator of theUser. Used to differentiate between users with the same usernames.
 This only contains the 4 digits after the username and the #.For most users, no discriminator is used and this will be "0000"instead. The primary use-case for discriminators is bot and guest accounts, to prevent name squatting.- Returns:
- Never-null String containing the Userdiscriminator.
 
- 
getAvatarIdThe Discord ID for this user's avatar image. If the user has not set an image, this will return null.- Returns:
- Possibly-null String containing the Useravatar id.
 
- 
getAvatarUrlThe URL for the user's avatar image. If the user has not set an image, this will return null.- Returns:
- Possibly-null String containing the Useravatar url.
 
- 
getAvatarReturns anImageProxyfor this user's avatar.- Returns:
- Possibly-null ImageProxyof this user's avatar
- See Also:
 
- 
getEffectiveAvatarUrlThe URL for the user's avatar image. If they do not have an avatar set, this will return the URL of their default avatar- Returns:
- Never-null String containing the Usereffective avatar url.
 
- 
getEffectiveAvatarReturns anImageProxyfor this user's effective avatar image.- Returns:
- Never-null ImageProxyof this user's effective avatar image
- See Also:
 
- 
retrieveProfileLoads the user'sUser.Profiledata. Returns a completed RestAction if this User has been retrieved usingJDA.retrieveUserById(long). You can useuseCache(false)to force the request for a new profile with up-to-date information.- Returns:
- CacheRestAction- Type:- User.Profile
 
- 
getAsTagThe "tag" for this userThis is the equivalent of calling String.format("%#s", user)Users without a discriminator use #0000instead.- Returns:
- Never-null String containing the tag for this user, for example DV8FromTheWorld#6297
 
- 
hasPrivateChannelboolean hasPrivateChannel()Whether or not the currently logged in user and this user have a currently openPrivateChannelor not.- Returns:
- True if the logged in account shares a PrivateChannel with this user.
 
- 
openPrivateChannelOpens aPrivateChannelwith this User.
 If a channel has already been opened with this user, it is immediately returned in the RestAction's success consumer without contacting the Discord API. You can useuseCache(false)to force the request for a new channel object, which is rarely useful since the channel id never changes.Examples 
 // Send message without response handling public void sendMessage(User user, String content) { user.openPrivateChannel() .flatMap(channel -> channel.sendMessage(content)) .queue(); } // Send message and delete 30 seconds later public RestAction<Void> sendSecretMessage(User user, String content) { return user.openPrivateChannel() // RestAction<PrivateChannel> .flatMap(channel -> channel.sendMessage(content)) // RestAction<Message> .delay(30, TimeUnit.SECONDS) // RestAction<Message> with delayed response .flatMap(Message::delete); // RestAction<Void> (executed 30 seconds after sending) }- Returns:
- CacheRestAction- Type:- PrivateChannel
 Retrieves the PrivateChannel to use to directly message this User.
- Throws:
- UnsupportedOperationException- If the recipient User is the currently logged in account (represented by- SelfUser) or if the user was created with- fromId(long)
- See Also:
 
- 
getMutualGuildsFinds and collects allGuildinstances that contain thisUserwithin the currentJDAinstance.
 This method is a shortcut for JDA.getMutualGuilds(User).- Returns:
- Immutable list of all Guildsthat this user is a member of.
 
- 
isBotboolean isBot()Returns whether or not the given user is a Bot-Account (special badge in client, some different behaviour)- Returns:
- If the User's Account is marked as Bot
 
- 
isSystemboolean isSystem()Returns whether or not the given user is a System account, which includes the urgent message account and the community updates bot.- Returns:
- Whether the User's account is marked as System
 
- 
getJDAReturns theJDAinstance of this User- Returns:
- the corresponding JDA instance
 
- 
getFlagsReturns theUserFlagsof this user.- Returns:
- EnumSet containing the flags of the user.
 
- 
getFlagsRawint getFlagsRaw()Returns the bitmask representation of theUserFlagsof this user.- Returns:
- bitmask representation of the user's flags.
 
 
-