Skip to main content
Represents a Discord Guild (Server). Contains all information provided from Discord about a Guild.

Overview

The Guild interface provides access to all guild-specific data including members, channels, roles, and guild settings.

Key Methods

Guild Information

getName()
String
The human readable name of the Guild.
String name = guild.getName();
getIdLong()
long
The Snowflake id of this Guild.
long guildId = guild.getIdLong();
getDescription()
String
The description for this guild. This is displayed in the server browser below the guild name for verified guilds.Returns null if no description is set.
String description = guild.getDescription();
getLocale()
DiscordLocale
The preferred locale for this guild.Defaults to DiscordLocale.ENGLISH_US
DiscordLocale locale = guild.getLocale();

Guild Assets

getIconId()
String
The Discord hash-id of the Guild icon image. Returns null if no icon has been set.
String iconId = guild.getIconId();
getIconUrl()
String
The URL of the Guild icon image. Returns null if no icon has been set.
String iconUrl = guild.getIconUrl();
getBannerId()
String
The guild banner id. This is shown in guilds below the guild name.Returns null if no banner is set.
String bannerId = guild.getBannerId();
getSplashId()
String
The Discord hash-id of the splash image for this Guild. A Splash image is displayed when viewing a Discord Guild Invite.Returns null if no splash has been set.
String splashId = guild.getSplashId();

Members

getMemberCount()
int
The expected member count for this guild. If the guild is not lazy loaded, this should be identical to the size of the member cache.
int memberCount = guild.getMemberCount();
getMemberById(long userId)
Member
Gets a Member object by user id.Returns null if no member with that id exists in this guild.
Member member = guild.getMemberById(123456789L);
getMemberCache()
MemberCacheView
A cache view of all Members in this Guild.
MemberCacheView members = guild.getMemberCache();
retrieveMemberById(String id)
RestAction<Member>
Retrieves a member by their user id.
guild.retrieveMemberById("123456789")
    .queue(member -> {
        System.out.println("Found: " + member.getEffectiveName());
    });
loadMembers()
Task<List<Member>>
Loads all members of this guild. This requires the GUILD_MEMBERS intent.
guild.loadMembers()
    .onSuccess(members -> {
        System.out.println("Loaded " + members.size() + " members");
    });

Roles

getRoles()
List<Role>
Gets all Roles in this Guild. The roles are ordered by their position descending (highest role first).
List<Role> roles = guild.getRoles();
getRoleById(long id)
Role
Gets a Role by its id.Returns null if no role with that id exists.
Role role = guild.getRoleById(123456789L);
getPublicRole()
Role
Gets the @everyone Role for this Guild.
Role publicRole = guild.getPublicRole();
createRole()
RoleAction
Creates a new Role in this Guild.
guild.createRole()
    .setName("Moderator")
    .setColor(Color.BLUE)
    .setPermissions(Permission.MESSAGE_MANAGE)
    .queue();

Channels

getChannels()
List<GuildChannel>
Gets all GuildChannels in this Guild.
List<GuildChannel> channels = guild.getChannels();
getTextChannels()
List<TextChannel>
Gets all TextChannels in this Guild.
List<TextChannel> textChannels = guild.getTextChannels();
getVoiceChannels()
List<VoiceChannel>
Gets all VoiceChannels in this Guild.
List<VoiceChannel> voiceChannels = guild.getVoiceChannels();
getChannelById(long id)
GuildChannel
Gets a GuildChannel by its id.Returns null if no channel with that id exists.
GuildChannel channel = guild.getChannelById(123456789L);

Guild Features

getFeatures()
Set<String>
The features of the Guild. Features can indicate special capabilities or requirements.
Set<String> features = guild.getFeatures();
if (features.contains("COMMUNITY")) {
    System.out.println("This is a community server");
}
getBoostTier()
BoostTier
The boost tier for this guild. Each tier unlocks new perks for a guild.
BoostTier tier = guild.getBoostTier();
getBoostCount()
int
The amount of boosts this server currently has.
int boostCount = guild.getBoostCount();
getBoosters()
List<Member>
Sorted list of Members that boost this guild. The list is sorted by time boosted ascending.
List<Member> boosters = guild.getBoosters();

Management

getManager()
GuildManager
The GuildManager for this Guild. Used to modify guild settings.
guild.getManager()
    .setName("New Server Name")
    .setDescription("A cool server")
    .queue();
ban(UserSnowflake user, int deletionTimeframe, TimeUnit unit)
AuditableRestAction<Void>
Bans a user from this Guild and deletes messages based on the deletion timeframe.
guild.ban(user, 7, TimeUnit.DAYS)
    .reason("Spam")
    .queue();
kick(UserSnowflake user)
AuditableRestAction<Void>
Kicks a Member from this Guild.
guild.kick(member)
    .reason("Rule violation")
    .queue();
addRoleToMember(UserSnowflake user, Role role)
AuditableRestAction<Void>
Adds a Role to a Member.
guild.addRoleToMember(member, role)
    .queue();
removeRoleFromMember(UserSnowflake user, Role role)
AuditableRestAction<Void>
Removes a Role from a Member.
guild.removeRoleFromMember(member, role)
    .queue();

Usage Example

// Get guild information
Guild guild = event.getGuild();
System.out.println("Server: " + guild.getName());
System.out.println("Members: " + guild.getMemberCount());
System.out.println("Boost Level: " + guild.getBoostTier());

// Manage members
guild.retrieveMemberById(userId)
    .queue(member -> {
        guild.addRoleToMember(member, moderatorRole).queue();
    });

// Create a channel
guild.createTextChannel("new-channel")
    .setTopic("Welcome to the new channel!")
    .queue();

// Update guild settings
guild.getManager()
    .setName("Updated Server Name")
    .setIcon(Icon.from(file))
    .queue();

See Also

Build docs developers (and LLMs) love