Class User

java.lang.Object
discord4j.core.object.entity.User
All Implemented Interfaces:
DiscordObject, Entity
Direct Known Subclasses:
PartialMember

public class User extends Object implements Entity
A Discord user.
See Also:
  • Constructor Details

    • User

      public User(GatewayDiscordClient gateway, discord4j.discordjson.json.UserData data)
      Constructs an User with an associated GatewayDiscordClient and Discord data.
      Parameters:
      gateway - The GatewayDiscordClient associated to this object, must be non-null.
      data - The raw data as represented by Discord, must be non-null.
  • Method Details

    • getClient

      public final GatewayDiscordClient getClient()
      Description copied from interface: DiscordObject
      Returns the GatewayDiscordClient that created this object. Methods in it are exclusively based on the entity cache or Store in use. Refer to calling getClient().rest() to access a DiscordClient that is capable of requesting entities directly from the REST API.
      Specified by:
      getClient in interface DiscordObject
      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.
    • getGlobalName

      public final Optional<String> getGlobalName()
      Gets the user's global username, not enforced to be unique across the platform. May be empty if the user has not set a global username.
      Returns:
      The user's global name
    • getUsername

      public final String getUsername()
      Gets the user's username. May or may not be unique across the platform (due to the system ongoing change)
      Returns:
      The user's username, not unique across the platform.
    • getDiscriminator

      @Deprecated @Nullable public final String getDiscriminator()
      Deprecated.
      This method will be removed once the system change is complete.
      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. Migrated users from the old system will have a discriminator of "0". May become null after the system change is complete.
      Returns:
      The user's 4-digit discriminator, or "0" if the user is migrated to the new system.
    • getTag

      public final String getTag()
      Gets the user's username and discriminator separated by a # or its username if the user is using the new system
      Returns:
      getUsername()#getDiscriminator() if the user is not migrated, getUsername() otherwise.
    • 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 by getAvatarUrl(Image.Format).
      Returns:
      A Mono where, upon successful completion, emits the avatar of the user. If an error is received, it is emitted through the Mono.
    • getAvatar

      public final Mono<Image> getAvatar()
      Gets the user's effective avatar. This is the avatar at the url given by getAvatarUrl().
      Returns:
      A Mono where, upon successful completion, emits the avatar of the user. If an error is received, it is emitted through the Mono.
    • getDefaultAvatarUrl

      public final String getDefaultAvatarUrl()
      Gets the default avatar URL for this user.
      Returns:
      The default avatar URL for this user.
    • hasAnimatedBanner

      public final boolean hasAnimatedBanner()
      Gets if the user's banner is animated.
      Returns:
      true if the user's banner is animated, false otherwise.
    • getBannerUrl

      public final Optional<String> getBannerUrl(Image.Format format)
      Gets the user's banner URL, if present.
      Parameters:
      format - The format for the URL.
      Returns:
      The user's banner URL, if present.
    • getBannerUrl

      public final Optional<String> getBannerUrl()
      Gets the user's effective banner URL.
      Returns:
      The user's effective banner URL.
    • getBanner

      public Mono<Image> getBanner(Image.Format format)
      Gets the user's banner. This is the banner at the url given by getBannerUrl(Image.Format).
      Returns:
      A Mono where, upon successful completion, emits the banner of the user. If an error is received, it is emitted through the Mono.
    • getBanner

      public final Mono<Image> getBanner()
      Gets the user's effective banner. This is the banner at the url given by getBannerUrl().
      Returns:
      A Mono where, upon successful completion, emits the banner of the user. If an error is received, it is emitted through the Mono.
    • getAccentColor

      public final Optional<Color> getAccentColor()
      Gets the user's banner accent color, if present.
      Returns:
      The user's banner accent color, if present.
    • 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.
      Specified by:
      getId in interface Entity
      Returns:
      The Snowflake that uniquely identifies this entity.
    • asMember

      public Mono<Member> asMember(Snowflake guildId)
      Requests to retrieve this user as a Member.
      Parameters:
      guildId - The ID of the guild to associate this user as a Member.
      Returns:
      A Mono where, upon successful completion, emits this user as a member. If an error is received, it is emitted through the Mono.
    • asMember

      public Mono<Member> asMember(Snowflake guildId, EntityRetrievalStrategy retrievalStrategy)
      Requests to retrieve this user as a Member, using the given retrieval strategy.
      Parameters:
      guildId - The ID of the guild to associate this user as a Member.
      retrievalStrategy - the strategy to use to get the member
      Returns:
      A Mono where, upon successful completion, emits this user as a member. If an error is received, it is emitted through the Mono.
    • getPrivateChannel

      public final Mono<PrivateChannel> getPrivateChannel()
      Requests to retrieve the private channel (DM) to this user.
      Returns:
      A Mono where, upon successful completion, emits the private channel to this user. If an error is received, it is emitted through the Mono.
    • getPublicFlags

      public EnumSet<User.Flag> getPublicFlags()
      Returns the public flags of this User, describing its features.
      Returns:
      A EnumSet with the public flags of this user.
    • equals

      public final boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object