Package discord4j.core.object.entity
Class User
- java.lang.Object
-
- discord4j.core.object.entity.User
-
- All Implemented Interfaces:
DiscordObject
,Entity
- Direct Known Subclasses:
Member
public class User extends Object implements Entity
A Discord user.- See Also:
- Users Resource
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
User.Flag
Describes the flags of a user.
-
Constructor Summary
Constructors Constructor Description User(GatewayDiscordClient gateway, discord4j.discordjson.json.UserData data)
Constructs anUser
with an associatedGatewayDiscordClient
and Discord data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Mono<Member>
asMember(Snowflake guildId)
Requests to retrieve this user as aMember
.Mono<Member>
asMember(Snowflake guildId, EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve this user as aMember
, using the given retrieval strategy.boolean
equals(Object obj)
Mono<Image>
getAvatar()
Gets the user's effective avatar.Mono<Image>
getAvatar(Image.Format format)
Gets the user's avatar.String
getAvatarUrl()
Gets the user's effective avatar URL.Optional<String>
getAvatarUrl(Image.Format format)
Gets the user's avatar URL, if present.GatewayDiscordClient
getClient()
Returns theGatewayDiscordClient
that created this object.String
getDefaultAvatarUrl()
Gets the default avatar URL for this user.String
getDiscriminator()
Gets the user's 4-digit discriminator The discriminator is unique number to distinct one among all users with the same username.Snowflake
getId()
Gets the Snowflake that uniquely identifies this entity.String
getMention()
Gets the raw mention.Mono<PrivateChannel>
getPrivateChannel()
Requests to retrieve the private channel (DM) to this user.EnumSet<User.Flag>
getPublicFlags()
Returns the public flags of thisUser
, describing its features.String
getTag()
Gets the user's username and discriminator separated by a # This is unique across the discord platform, but may change.discord4j.discordjson.json.UserData
getUserData()
Gets the data of the user.String
getUsername()
Gets the user's username, not unique across the platform.boolean
hasAnimatedAvatar()
Gets if the user's avatar is animated.int
hashCode()
boolean
isBot()
Gets whether the user is a bot.String
toString()
-
-
-
Constructor Detail
-
User
public User(GatewayDiscordClient gateway, discord4j.discordjson.json.UserData data)
Constructs anUser
with an associatedGatewayDiscordClient
and Discord data.- Parameters:
gateway
- TheGatewayDiscordClient
associated to this object, must be non-null.data
- The raw data as represented by Discord, must be non-null.
-
-
Method Detail
-
getClient
public final GatewayDiscordClient getClient()
Description copied from interface:DiscordObject
Returns theGatewayDiscordClient
that created this object. Methods in it are exclusively based on the entity cache orStore
in use. Refer to callinggetClient().rest()
to access aDiscordClient
that is capable of requesting entities directly from the REST API.- Specified by:
getClient
in interfaceDiscordObject
- Returns:
- The
GatewayDiscordClient
associated to this object.
-
getUserData
public discord4j.discordjson.json.UserData getUserData()
Gets the data of the user.- Returns:
- The data of the user.
-
getUsername
public final String getUsername()
Gets the user's username, not unique across the platform.- Returns:
- The user's username, not unique across the platform.
-
getDiscriminator
public final String getDiscriminator()
Gets the user's 4-digit discriminator The discriminator is unique number to distinct one among all users with the same username. The discriminator is randomly generated, but can be changed if the user has a nitro subscription.- Returns:
- The user's 4-digit discriminator.
-
getTag
public final String getTag()
Gets the user's username and discriminator separated by a # This is unique across the discord platform, but may change.- Returns:
getUsername()
#getDiscriminator()
-
hasAnimatedAvatar
public final boolean hasAnimatedAvatar()
Gets if the user's avatar is animated.- Returns:
true
if the user's avatar is animated,false
otherwise.
-
getAvatarUrl
public final Optional<String> getAvatarUrl(Image.Format format)
Gets the user's avatar URL, if present.- Parameters:
format
- The format for the URL.- Returns:
- The user's avatar URL, if present.
-
getAvatarUrl
public final String getAvatarUrl()
Gets the user's effective avatar URL.- Returns:
- The user's effective avatar URL.
-
getAvatar
public Mono<Image> getAvatar(Image.Format format)
Gets the user's avatar. This is the avatar at the url given bygetAvatarUrl(Image.Format)
.
-
getAvatar
public final Mono<Image> getAvatar()
Gets the user's effective avatar. This is the avatar at the url given bygetAvatarUrl()
.
-
getDefaultAvatarUrl
public final String getDefaultAvatarUrl()
Gets the default avatar URL for this user.- Returns:
- The default avatar URL for this user.
-
isBot
public boolean isBot()
Gets whether the user is a bot.- Returns:
true
if this user is a bot,false
otherwise.
-
getMention
public final String getMention()
Gets the raw mention. This is the format utilized to directly mention another user (assuming the user exists in context of the mention).- Returns:
- The raw mention.
-
getId
public final Snowflake getId()
Description copied from interface:Entity
Gets the Snowflake that uniquely identifies this entity.
-
asMember
public Mono<Member> asMember(Snowflake guildId)
Requests to retrieve this user as aMember
.
-
asMember
public Mono<Member> asMember(Snowflake guildId, EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve this user as aMember
, using the given retrieval strategy.
-
getPrivateChannel
public final Mono<PrivateChannel> getPrivateChannel()
Requests to retrieve the private channel (DM) to this user.- Returns:
- A
Mono
where, upon successful completion, emits theprivate channel
to this user. If an error is received, it is emitted through theMono
.
-
getPublicFlags
public EnumSet<User.Flag> getPublicFlags()
Returns the public flags of thisUser
, describing its features.- Returns:
- A
EnumSet
with the public flags of this user.
-
-