Package net.dv8tion.jda.api.entities
Interface User
-
- All Superinterfaces:
Formattable
,IFakeable
,IMentionable
,ISnowflake
- All Known Subinterfaces:
SelfUser
public interface User extends IMentionable, IFakeable
Represents a Discord User. Contains all publicly available information about a specific Discord User.Formattable
This interface extendsFormattable
and can be used with aFormatter
such as used byString.format(String, Object...)
orPrintStream.printf(String, Object...)
.This will use
IMentionable.getAsMention()
rather thanObject.toString()
!
Supported Features:- Alternative
- Uses the Discord Tag (Username#Discriminator) instead (Example:%#s
- results in
)getName()
#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
!
-
-
Field Summary
Fields Modifier and Type Field Description static String
AVATAR_URL
Template forgetAvatarUrl()
.static String
DEFAULT_AVATAR_URL
Template forgetDefaultAvatarUrl()
static Pattern
USER_TAG
Compiled pattern for a Discord Tag:(.{2,32})#(\d{4})
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description String
getAsTag()
The "tag" for this userString
getAvatarId()
The Discord Id for this user's avatar image.default String
getAvatarUrl()
The URL for the user's avatar image.String
getDefaultAvatarId()
The Discord Id for this user's default avatar image.default String
getDefaultAvatarUrl()
The URL for the for the user's default avatar image.String
getDiscriminator()
The discriminator of theUser
.default String
getEffectiveAvatarUrl()
The URL for the user's avatar image If they do not have an avatar set, this will return the URL of their default avatarJDA
getJDA()
Returns theJDA
instance of this UserList<Guild>
getMutualGuilds()
String
getName()
The username of theUser
.boolean
hasPrivateChannel()
Whether or not the currently logged in user and this user have a currently openPrivateChannel
or not.boolean
isBot()
Returns whether or not the given user is a Bot-Account (special badge in client, some different behaviour)RestAction<PrivateChannel>
openPrivateChannel()
Opens aPrivateChannel
with this User.-
Methods inherited from interface net.dv8tion.jda.api.entities.IMentionable
formatTo, getAsMention
-
Methods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getIdLong, getTimeCreated
-
-
-
-
Field Detail
-
USER_TAG
static final Pattern USER_TAG
Compiled pattern for a Discord Tag:(.{2,32})#(\d{4})
-
AVATAR_URL
static final String AVATAR_URL
Template forgetAvatarUrl()
.- See Also:
- Constant Field Values
-
DEFAULT_AVATAR_URL
static final String DEFAULT_AVATAR_URL
Template forgetDefaultAvatarUrl()
- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
@Nonnull String getName()
The username of theUser
. Length is between 2 and 32 characters (inclusive).- Returns:
- Never-null String containing the
User
's username.
-
getDiscriminator
@Nonnull String getDiscriminator()
The discriminator of theUser
. Used to differentiate between users with the same usernames.
This only contains the 4 digits after the username and the #. Ex: 6297- Returns:
- Never-null String containing the
User
discriminator.
-
getAvatarId
@Nullable String getAvatarId()
The 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
User
avatar id.
-
getAvatarUrl
@Nullable default String getAvatarUrl()
The 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
User
avatar url.
-
getDefaultAvatarId
@Nonnull String getDefaultAvatarId()
The Discord Id for this user's default avatar image.- Returns:
- Never-null String containing the
User
default avatar id.
-
getDefaultAvatarUrl
@Nonnull default String getDefaultAvatarUrl()
The URL for the for the user's default avatar image.- Returns:
- Never-null String containing the
User
default avatar url.
-
getEffectiveAvatarUrl
@Nonnull default String getEffectiveAvatarUrl()
The 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
User
effective avatar url.
-
getAsTag
@Nonnull String getAsTag()
The "tag" for this userThis is the equivalent of calling
String.format
("%#s", user)- Returns:
- Never-null String containing the tag for this user, for example DV8FromTheWorld#6297
-
hasPrivateChannel
boolean hasPrivateChannel()
Whether or not the currently logged in user and this user have a currently openPrivateChannel
or not.- Returns:
- True if the logged in account shares a PrivateChannel with this user.
-
openPrivateChannel
@Nonnull @CheckReturnValue RestAction<PrivateChannel> openPrivateChannel()
Opens aPrivateChannel
with 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.Examples
// Send message without response handling public void sendMessage(User user, String content) { user.openPrivateChannel().queue(channel -> channel.sendMessage(content).queue()); } // Send message and provide it to the future for further handling public CompletableFuture<Message> awaitMessage(User user, String content) { return user.openPrivateChannel().submit() .thenCompose(channel -> channel.sendMessage(content).submit()) .whenComplete((m, error) -> { if (error != null) error.printStackTrace()); }); }
- Returns:
RestAction
- 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 bySelfUser
)IllegalStateException
- If this User isfake
-
getMutualGuilds
@Nonnull List<Guild> getMutualGuilds()
Finds and collects allGuild
instances that contain thisUser
within the currentJDA
instance.
This method is a shortcut for
JDA.getMutualGuilds(User)
.- Returns:
- Immutable list of all
Guilds
that this user is a member of.
-
isBot
boolean 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
-
-