Skip to main content
Represents a Discord User. Contains all publicly available information about a specific Discord User.

Overview

The User interface represents a Discord user account across the entire platform. For guild-specific user information, see Member.

Key Properties

Basic Information

getId()
String
The Snowflake id of this User.
String userId = user.getId();
getIdLong()
long
The Snowflake id of this User as a primitive long.
long userId = user.getIdLong();
getName()
String
The username of the User. Length is between 2 and 32 characters (inclusive).
String username = user.getName();
getGlobalName()
String
The global display name of the user. This name is not unique and allows more characters.Returns null if unset.
String globalName = user.getGlobalName();
getEffectiveName()
String
The name visible in the UI. If the global name is null, this returns the username instead.
String displayName = user.getEffectiveName();
getDiscriminator()
String
The discriminator of the User. Used to differentiate between users with the same usernames.For most users, this will be "0000". The primary use-case for discriminators is bot and guest accounts.
String discriminator = user.getDiscriminator();
getAsTag()
String
The “tag” for this user (username#discriminator).Users without a discriminator use #0000 instead.
String tag = user.getAsTag(); // Example: "Username#0000"

Avatar and Profile

getAvatarId()
String
The Discord ID for this user’s avatar image.Returns null if the user has not set an avatar.
String avatarId = user.getAvatarId();
getAvatarUrl()
String
The URL for the user’s avatar image.Returns null if the user has not set an avatar.
String avatarUrl = user.getAvatarUrl();
getEffectiveAvatarUrl()
String
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.
String avatarUrl = user.getEffectiveAvatarUrl();
getDefaultAvatarUrl()
String
The URL for the user’s default avatar image.
String defaultAvatar = user.getDefaultAvatarUrl();

Account Type

isBot()
boolean
Returns whether or not the given user is a Bot account (special badge in client, some different behavior).
if (user.isBot()) {
    System.out.println("This is a bot account");
}
isSystem()
boolean
Returns whether or not the given user is a System account, which includes the urgent message account and the community updates bot.
if (user.isSystem()) {
    System.out.println("This is a system account");
}

User Flags

getFlags()
EnumSet<UserFlag>
Returns the UserFlags of this user.
EnumSet<UserFlag> flags = user.getFlags();
if (flags.contains(UserFlag.VERIFIED_DEVELOPER)) {
    System.out.println("Verified bot developer");
}
getFlagsRaw()
int
Returns the bitmask representation of the UserFlags of this user.
int flagsBitmask = user.getFlagsRaw();

User Actions

Direct Messaging

openPrivateChannel()
CacheRestAction<PrivateChannel>
Opens a PrivateChannel with this User.If a channel has already been opened, it is immediately returned without contacting the Discord API.
user.openPrivateChannel()
    .flatMap(channel -> channel.sendMessage("Hello!"))
    .queue();
hasPrivateChannel()
boolean
Whether the currently logged in user and this user have a currently open PrivateChannel.
if (user.hasPrivateChannel()) {
    System.out.println("DM channel exists");
}

Profile Data

retrieveProfile()
CacheRestAction<Profile>
Loads the user’s Profile data including banner and accent color.
user.retrieveProfile()
    .queue(profile -> {
        Color accent = profile.getAccentColor();
        String banner = profile.getBannerUrl();
    });

Guild Information

getMutualGuilds()
List<Guild>
Finds and collects all Guild instances that contain this User within the current JDA instance.
List<Guild> mutualGuilds = user.getMutualGuilds();
System.out.println("Mutual servers: " + mutualGuilds.size());

Static Methods

User.fromId(long id)
UserSnowflake
Creates a User instance which only wraps an ID.Useful for operations that only require a user ID.
UserSnowflake user = User.fromId(123456789L);
guild.ban(user).queue();
User.fromId(String id)
UserSnowflake
Creates a User instance which only wraps an ID (string version).
UserSnowflake user = User.fromId("123456789");

User.Profile

The Profile class contains additional user information that requires an API request.
getBannerId()
String
The Discord Id for this user’s banner image.Returns null if the user has not set a banner.
getBannerUrl()
String
The URL for the user’s banner image.Returns null if the user has not set a banner.
getAccentColor()
Color
The user’s accent color.Returns null if the user has not set an accent color.
getAccentColorRaw()
int
The raw RGB value of this user’s accent color.Defaults to User.DEFAULT_ACCENT_COLOR_RAW if not available.

User Flags

The UserFlag enum represents public badges and account types:
  • STAFF - Discord Employee
  • PARTNER - Partnered Server Owner
  • HYPESQUAD - HypeSquad Events
  • BUG_HUNTER_LEVEL_1 - Bug Hunter Level 1
  • BUG_HUNTER_LEVEL_2 - Bug Hunter Level 2
  • HYPESQUAD_BRAVERY - HypeSquad Bravery
  • HYPESQUAD_BRILLIANCE - HypeSquad Brilliance
  • HYPESQUAD_BALANCE - HypeSquad Balance
  • EARLY_SUPPORTER - Early Supporter
  • VERIFIED_BOT - Verified Bot
  • VERIFIED_DEVELOPER - Early Verified Bot Developer
  • CERTIFIED_MODERATOR - Discord Certified Moderator
  • BOT_HTTP_INTERACTIONS - HTTP Interactions Bot
  • ACTIVE_DEVELOPER - Active Developer

Usage Example

// Get user information
User user = event.getAuthor();
System.out.println("Username: " + user.getName());
System.out.println("Tag: " + user.getAsTag());
System.out.println("ID: " + user.getId());

// Check if bot
if (user.isBot()) {
    return; // Ignore bot messages
}

// Send DM
user.openPrivateChannel()
    .flatMap(channel -> channel.sendMessage("Hello!")
    .queue();

// Get profile with banner
user.retrieveProfile()
    .queue(profile -> {
        String banner = profile.getBannerUrl();
        if (banner != null) {
            System.out.println("Banner: " + banner);
        }
    });

// Check flags
EnumSet<UserFlag> flags = user.getFlags();
if (flags.contains(UserFlag.VERIFIED_DEVELOPER)) {
    System.out.println("This user is a verified bot developer!");
}

// Get mutual servers
List<Guild> mutualGuilds = user.getMutualGuilds();
System.out.println("Shared servers: " + mutualGuilds.size());

See Also

Build docs developers (and LLMs) love