Interface User

  • All Superinterfaces:
    java.util.Formattable, IFakeable, IMentionable, ISnowflake
    All Known Subinterfaces:
    SelfUser

    public interface User
    extends ISnowflake, IMentionable, IFakeable
    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 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!

    • Method Detail

      • getName

        java.lang.String getName()
        The username of the User. Length is between 2 and 32 characters (inclusive).
        Returns:
        Never-null String containing the User's username.
      • getDiscriminator

        java.lang.String getDiscriminator()

        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 #. Ex: 6297
        Returns:
        Never-null String containing the User discriminator.
      • getAvatarId

        java.lang.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

        java.lang.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

        java.lang.String getDefaultAvatarId()
        The Discord Id for this user's default avatar image.
        Returns:
        Never-null String containing the User default avatar id.
      • getDefaultAvatarUrl

        java.lang.String getDefaultAvatarUrl()
        The URL for the for the user's default avatar image.
        Returns:
        Never-null String containing the User default avatar url.
      • getEffectiveAvatarUrl

        java.lang.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.
      • hasPrivateChannel

        boolean hasPrivateChannel()
        Whether or not the currently logged in user and this user have a currently open PrivateChannel or not.
        Returns:
        True if the logged in account shares a PrivateChannel with this user.
      • openPrivateChannel

        @CheckReturnValue
        RestAction<PrivateChannel> openPrivateChannel()
        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.

        The following ErrorResponses are possible:

        Returns:
        RestAction - Type: PrivateChannel
        The PrivateChannel to use to directly message this User.
        Throws:
        java.lang.UnsupportedOperationException - If the recipient User is the currently logged in account (represented by SelfUser)
        java.lang.IllegalStateException - If this User is fake
      • getMutualGuilds

        java.util.List<Guild> getMutualGuilds()
        Finds and collects all Guild instances that contain this User within the current JDA instance.

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

        Returns:
        Unmodifiable 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
      • getJDA

        JDA getJDA()
        Returns the JDA instance of this User
        Returns:
        the corresponding JDA instance