Class UserImpl

java.lang.Object
net.dv8tion.jda.internal.entities.UserSnowflakeImpl
net.dv8tion.jda.internal.entities.UserImpl
All Implemented Interfaces:
Formattable, IMentionable, ISnowflake, User, UserSnowflake
Direct Known Subclasses:
SelfUserImpl

public class UserImpl extends UserSnowflakeImpl implements User
  • Constructor Details

    • UserImpl

      public UserImpl(long id, JDAImpl api)
  • Method Details

    • getName

      @Nonnull public String getName()
      Description copied from interface: User
      The username of the User. Length is between 2 and 32 characters (inclusive).
      Specified by:
      getName in interface User
      Returns:
      Never-null String containing the User's username.
    • getGlobalName

      @Nullable public String getGlobalName()
      Description copied from interface: User
      The global display name of the user.
      This name is not unique and allows more characters.

      This name is usually displayed in the UI.

      Specified by:
      getGlobalName in interface User
      Returns:
      The global display name or null if unset.
    • getDiscriminator

      @Nonnull public String getDiscriminator()
      Description copied from interface: User
      The discriminator of the User. 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.

      Specified by:
      getDiscriminator in interface User
      Returns:
      Never-null String containing the User discriminator.
    • getAvatarId

      @Nullable public String getAvatarId()
      Description copied from interface: User
      The Discord ID for this user's avatar image. If the user has not set an image, this will return null.
      Specified by:
      getAvatarId in interface User
      Returns:
      Possibly-null String containing the User avatar id.
    • retrieveProfile

      @Nonnull public CacheRestAction<User.Profile> retrieveProfile()
      Description copied from interface: User
      Loads the user's User.Profile data. Returns a completed RestAction if this User has been retrieved using JDA.retrieveUserById(long). You can use useCache(false) to force the request for a new profile with up-to-date information.
      Specified by:
      retrieveProfile in interface User
      Returns:
      CacheRestAction - Type: User.Profile
    • getProfile

      public User.Profile getProfile()
    • getDefaultAvatarId

      @Nonnull public String getDefaultAvatarId()
      Description copied from interface: UserSnowflake
      The Discord ID for this user's default avatar image.
      Specified by:
      getDefaultAvatarId in interface UserSnowflake
      Overrides:
      getDefaultAvatarId in class UserSnowflakeImpl
      Returns:
      Never-null String containing the user's default avatar id.
    • getAsTag

      @Nonnull public String getAsTag()
      Description copied from interface: User
      The "tag" for this user

      This is the equivalent of calling String.format("%#s", user)

      Users without a discriminator use #0000 instead.

      Specified by:
      getAsTag in interface User
      Returns:
      Never-null String containing the tag for this user, for example DV8FromTheWorld#6297
    • hasPrivateChannel

      public boolean hasPrivateChannel()
      Description copied from interface: User
      Whether or not the currently logged in user and this user have a currently open PrivateChannel or not.
      Specified by:
      hasPrivateChannel in interface User
      Returns:
      True if the logged in account shares a PrivateChannel with this user.
    • openPrivateChannel

      @Nonnull public CacheRestAction<PrivateChannel> openPrivateChannel()
      Description copied from interface: User
      Opens a PrivateChannel 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. You can use useCache(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)
       }
       
      Specified by:
      openPrivateChannel in interface User
      Returns:
      CacheRestAction - Type: PrivateChannel
      Retrieves the PrivateChannel to use to directly message this User.
      See Also:
    • getPrivateChannel

      public PrivateChannel getPrivateChannel()
    • getMutualGuilds

      @Nonnull public List<Guild> getMutualGuilds()
      Description copied from interface: User
      Finds and collects all Guild instances that contain this User within the current JDA instance.

      This method is a shortcut for JDA.getMutualGuilds(User).

      Specified by:
      getMutualGuilds in interface User
      Returns:
      Immutable list of all Guilds that this user is a member of.
    • isBot

      public boolean isBot()
      Description copied from interface: User
      Returns whether or not the given user is a Bot-Account (special badge in client, some different behaviour)
      Specified by:
      isBot in interface User
      Returns:
      If the User's Account is marked as Bot
    • isSystem

      public boolean isSystem()
      Description copied from interface: User
      Returns whether or not the given user is a System account, which includes the urgent message account and the community updates bot.
      Specified by:
      isSystem in interface User
      Returns:
      Whether the User's account is marked as System
    • getJDA

      @Nonnull public JDAImpl getJDA()
      Description copied from interface: User
      Returns the JDA instance of this User
      Specified by:
      getJDA in interface User
      Returns:
      the corresponding JDA instance
    • getFlags

      @Nonnull public EnumSet<User.UserFlag> getFlags()
      Description copied from interface: User
      Returns the UserFlags of this user.
      Specified by:
      getFlags in interface User
      Returns:
      EnumSet containing the flags of the user.
    • getFlagsRaw

      public int getFlagsRaw()
      Description copied from interface: User
      Returns the bitmask representation of the UserFlags of this user.
      Specified by:
      getFlagsRaw in interface User
      Returns:
      bitmask representation of the user's flags.
    • toString

      public String toString()
      Overrides:
      toString in class UserSnowflakeImpl
    • setName

      public UserImpl setName(String name)
    • setGlobalName

      public UserImpl setGlobalName(String globalName)
    • setDiscriminator

      public UserImpl setDiscriminator(short discriminator)
    • setAvatarId

      public UserImpl setAvatarId(String avatarId)
    • setProfile

      public UserImpl setProfile(User.Profile profile)
    • setPrivateChannel

      public UserImpl setPrivateChannel(PrivateChannel privateChannel)
    • setBot

      public UserImpl setBot(boolean bot)
    • setSystem

      public UserImpl setSystem(boolean system)
    • setFlags

      public UserImpl setFlags(int flags)
    • getDiscriminatorInt

      public short getDiscriminatorInt()
    • formatTo

      public void formatTo(Formatter formatter, int flags, int width, int precision)
      Specified by:
      formatTo in interface Formattable
      Specified by:
      formatTo in interface IMentionable