All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.dv8tion.jda.api.entities.Guild Maven / Gradle / Ivy

Go to download

Java wrapper for the popular chat & VOIP service: Discord https://discord.com

There is a newer version: 5.1.0
Show newest version
/*
 * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.dv8tion.jda.api.entities;

import net.dv8tion.jda.annotations.DeprecatedSince;
import net.dv8tion.jda.annotations.ForRemoval;
import net.dv8tion.jda.annotations.Incubating;
import net.dv8tion.jda.annotations.ReplaceWith;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.Region;
import net.dv8tion.jda.api.entities.automod.AutoModResponse;
import net.dv8tion.jda.api.entities.automod.AutoModRule;
import net.dv8tion.jda.api.entities.automod.AutoModTriggerType;
import net.dv8tion.jda.api.entities.automod.build.AutoModRuleData;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.attribute.ICopyableChannel;
import net.dv8tion.jda.api.entities.channel.attribute.IGuildChannelContainer;
import net.dv8tion.jda.api.entities.channel.attribute.IInviteContainer;
import net.dv8tion.jda.api.entities.channel.concrete.*;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildChannel;
import net.dv8tion.jda.api.entities.channel.unions.DefaultGuildChannelUnion;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import net.dv8tion.jda.api.entities.sticker.*;
import net.dv8tion.jda.api.entities.templates.Template;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.interactions.DiscordLocale;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.PrivilegeConfig;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.privileges.IntegrationPrivilege;
import net.dv8tion.jda.api.managers.*;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.*;
import net.dv8tion.jda.api.requests.restaction.order.CategoryOrderAction;
import net.dv8tion.jda.api.requests.restaction.order.ChannelOrderAction;
import net.dv8tion.jda.api.requests.restaction.order.RoleOrderAction;
import net.dv8tion.jda.api.requests.restaction.pagination.AuditLogPaginationAction;
import net.dv8tion.jda.api.requests.restaction.pagination.BanPaginationAction;
import net.dv8tion.jda.api.requests.restaction.pagination.PaginationAction;
import net.dv8tion.jda.api.utils.FileUpload;
import net.dv8tion.jda.api.utils.ImageProxy;
import net.dv8tion.jda.api.utils.MiscUtil;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import net.dv8tion.jda.api.utils.cache.MemberCacheView;
import net.dv8tion.jda.api.utils.cache.SnowflakeCacheView;
import net.dv8tion.jda.api.utils.cache.SortedSnowflakeCacheView;
import net.dv8tion.jda.api.utils.concurrent.Task;
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import net.dv8tion.jda.internal.requests.DeferredRestAction;
import net.dv8tion.jda.internal.utils.Checks;
import net.dv8tion.jda.internal.utils.EntityString;
import net.dv8tion.jda.internal.utils.Helpers;
import net.dv8tion.jda.internal.utils.concurrent.task.GatewayTask;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.temporal.TemporalAccessor;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * Represents a Discord {@link net.dv8tion.jda.api.entities.Guild Guild}.
 * This should contain all information provided from Discord about a Guild.
 *
 * @see JDA#getGuildCache()
 * @see JDA#getGuildById(long)
 * @see JDA#getGuildsByName(String, boolean)
 * @see JDA#getGuilds()
 */
public interface Guild extends IGuildChannelContainer, ISnowflake
{
    /** Template for {@link #getIconUrl()}. */
    String ICON_URL = "https://cdn.discordapp.com/icons/%s/%s.%s";
    /** Template for {@link #getSplashUrl()}. */
    String SPLASH_URL = "https://cdn.discordapp.com/splashes/%s/%s.png";
    /** Template for {@link #getBannerUrl()}. */
    String BANNER_URL = "https://cdn.discordapp.com/banners/%s/%s.%s";

    /**
     * Retrieves the list of guild commands.
     * 
This list does not include global commands! Use {@link JDA#retrieveCommands()} for global commands. *
This list does not include localization data. Use {@link #retrieveCommands(boolean)} to get localization data * * @return {@link RestAction} - Type: {@link List} of {@link Command} */ @Nonnull @CheckReturnValue default RestAction> retrieveCommands() { return retrieveCommands(false); } /** * Retrieves the list of guild commands. *
This list does not include global commands! Use {@link JDA#retrieveCommands()} for global commands. * * @param withLocalizations * {@code true} if the localization data (such as name and description) should be included * * @return {@link RestAction} - Type: {@link List} of {@link Command} */ @Nonnull @CheckReturnValue RestAction> retrieveCommands(boolean withLocalizations); /** * Retrieves the existing {@link Command} instance by id. * *

If there is no command with the provided ID, * this RestAction fails with {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_COMMAND ErrorResponse.UNKNOWN_COMMAND} * * @param id * The command id * * @throws IllegalArgumentException * If the provided id is not a valid snowflake * * @return {@link RestAction} - Type: {@link Command} */ @Nonnull @CheckReturnValue RestAction retrieveCommandById(@Nonnull String id); /** * Retrieves the existing {@link Command} instance by id. * *

If there is no command with the provided ID, * this RestAction fails with {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_COMMAND ErrorResponse.UNKNOWN_COMMAND} * * @param id * The command id * * @return {@link RestAction} - Type: {@link Command} */ @Nonnull @CheckReturnValue default RestAction retrieveCommandById(long id) { return retrieveCommandById(Long.toUnsignedString(id)); } /** * Creates or updates a command. *
If a command with the same name exists, it will be replaced. * This operation is idempotent. * Commands will persist between restarts of your bot, you only have to create a command once. * *

To specify a complete list of all commands you can use {@link #updateCommands()} instead. * *

You need the OAuth2 scope {@code "applications.commands"} in order to add commands to a guild. * * @param command * The {@link CommandData} for the command * * @throws IllegalArgumentException * If null is provided * * @return {@link RestAction} - Type: {@link Command} *
The RestAction used to create or update the command * * @see Commands#slash(String, String) Commands.slash(...) * @see Commands#message(String) Commands.message(...) * @see Commands#user(String) Commands.user(...) */ @Nonnull @CheckReturnValue RestAction upsertCommand(@Nonnull CommandData command); /** * Creates or updates a slash command. *
If a command with the same name exists, it will be replaced. * This operation is idempotent. * Commands will persist between restarts of your bot, you only have to create a command once. * *

To specify a complete list of all commands you can use {@link #updateCommands()} instead. * *

You need the OAuth2 scope {@code "applications.commands"} in order to add commands to a guild. * * @param name * The lowercase alphanumeric (with dash) name, 1-32 characters * @param description * The description for the command, 1-100 characters * * @throws IllegalArgumentException * If null is provided or the name/description do not meet the requirements * * @return {@link CommandCreateAction} */ @Nonnull @CheckReturnValue default CommandCreateAction upsertCommand(@Nonnull String name, @Nonnull String description) { return (CommandCreateAction) upsertCommand(new CommandDataImpl(name, description)); } /** * Configures the complete list of guild commands. *
This will replace the existing command list for this guild. You should only use this at most once on startup! * *

This operation is idempotent. * Commands will persist between restarts of your bot, you only have to create a command once. * *

You need the OAuth2 scope {@code "applications.commands"} in order to add commands to a guild. * *

Examples * *

Set list to 2 commands: *

{@code
     * guild.updateCommands()
     *   .addCommands(Commands.slash("ping", "Gives the current ping"))
     *   .addCommands(Commands.slash("ban", "Ban the target user")
     *     .addOption(OptionType.USER, "user", "The user to ban", true))
     *     .setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.BAN_MEMBERS))
     *   .queue();
     * }
* *

Delete all commands: *

{@code
     * guild.updateCommands().queue();
     * }
* * @return {@link CommandListUpdateAction} * * @see JDA#updateCommands() */ @Nonnull @CheckReturnValue CommandListUpdateAction updateCommands(); /** * Edit an existing command by id. * *

If there is no command with the provided ID, * this RestAction fails with {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_COMMAND ErrorResponse.UNKNOWN_COMMAND} * * @param id * The id of the command to edit * * @throws IllegalArgumentException * If the provided id is not a valid snowflake * * @return {@link CommandEditAction} used to edit the command */ @Nonnull @CheckReturnValue CommandEditAction editCommandById(@Nonnull String id); /** * Edit an existing command by id. * *

If there is no command with the provided ID, * this RestAction fails with {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_COMMAND ErrorResponse.UNKNOWN_COMMAND} * * @param id * The id of the command to edit * * @return {@link CommandEditAction} used to edit the command */ @Nonnull @CheckReturnValue default CommandEditAction editCommandById(long id) { return editCommandById(Long.toUnsignedString(id)); } /** * Delete the command for this id. * *

If there is no command with the provided ID, * this RestAction fails with {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_COMMAND ErrorResponse.UNKNOWN_COMMAND} * * @param commandId * The id of the command that should be deleted * * @throws IllegalArgumentException * If the provided id is not a valid snowflake * * @return {@link RestAction} */ @Nonnull @CheckReturnValue RestAction deleteCommandById(@Nonnull String commandId); /** * Delete the command for this id. * *

If there is no command with the provided ID, * this RestAction fails with {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_COMMAND ErrorResponse.UNKNOWN_COMMAND} * * @param commandId * The id of the command that should be deleted * * @return {@link RestAction} */ @Nonnull @CheckReturnValue default RestAction deleteCommandById(long commandId) { return deleteCommandById(Long.toUnsignedString(commandId)); } /** * Retrieves the {@link IntegrationPrivilege IntegrationPrivileges} for the target with the specified ID. *
The ID can either be of a Command or Application! * *

Moderators of a guild can modify these privileges through the Integrations Menu * *

If there is no command or application with the provided ID, * this RestAction fails with {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_COMMAND ErrorResponse.UNKNOWN_COMMAND} * * @param targetId * The id of the command (global or guild), or application * * @throws IllegalArgumentException * If the id is not a valid snowflake * * @return {@link RestAction} - Type: {@link List} of {@link IntegrationPrivilege} */ @Nonnull @CheckReturnValue RestAction> retrieveIntegrationPrivilegesById(@Nonnull String targetId); /** * Retrieves the {@link IntegrationPrivilege IntegrationPrivileges} for the target with the specified ID. *
The ID can either be of a Command or Application! * *

Moderators of a guild can modify these privileges through the Integrations Menu * *

If there is no command or application with the provided ID, * this RestAction fails with {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_COMMAND ErrorResponse.UNKNOWN_COMMAND} * * @param targetId * The id of the command (global or guild), or application * * @throws IllegalArgumentException * If the id is not a valid snowflake * * @return {@link RestAction} - Type: {@link List} of {@link IntegrationPrivilege} */ @Nonnull @CheckReturnValue default RestAction> retrieveIntegrationPrivilegesById(long targetId) { return retrieveIntegrationPrivilegesById(Long.toUnsignedString(targetId)); } /** * Retrieves the {@link IntegrationPrivilege IntegrationPrivileges} for the commands in this guild. *
The RestAction provides a {@link PrivilegeConfig} providing the privileges of this application and its commands. * *

Moderators of a guild can modify these privileges through the Integrations Menu * * @return {@link RestAction} - Type: {@link PrivilegeConfig} */ @Nonnull @CheckReturnValue RestAction retrieveCommandPrivileges(); /** * Retrieves the available regions for this Guild *
Shortcut for {@link #retrieveRegions(boolean) retrieveRegions(true)} *
This will include deprecated voice regions by default. * * @return {@link RestAction RestAction} - Type {@link java.util.EnumSet EnumSet} */ @Nonnull @CheckReturnValue default RestAction> retrieveRegions() { return retrieveRegions(true); } /** * Retrieves the available regions for this Guild * * @param includeDeprecated * Whether to include deprecated regions * * @return {@link RestAction RestAction} - Type {@link java.util.EnumSet EnumSet} */ @Nonnull @CheckReturnValue RestAction> retrieveRegions(boolean includeDeprecated); /** * Retrieves all current {@link AutoModRule AutoModRules} for this guild. * * @throws InsufficientPermissionException * If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission * * @return {@link RestAction} - Type: {@link List} of {@link AutoModRule} */ @Nonnull @CheckReturnValue RestAction> retrieveAutoModRules(); /** * Retrieves the {@link AutoModRule} for the provided id. * * @param id * The id of the rule * * @throws IllegalArgumentException * If the provided id is not a valid snowflake * @throws InsufficientPermissionException * If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission * * @return {@link RestAction} - Type: {@link AutoModRule} */ @Nonnull @CheckReturnValue RestAction retrieveAutoModRuleById(@Nonnull String id); /** * Retrieves the {@link AutoModRule} for the provided id. * * @param id * The id of the rule * * @throws InsufficientPermissionException * If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission * * @return {@link RestAction} - Type: {@link AutoModRule} */ @Nonnull @CheckReturnValue default RestAction retrieveAutoModRuleById(long id) { return retrieveAutoModRuleById(Long.toUnsignedString(id)); } /** * Creates a new {@link AutoModRule} for this guild. * *

You can only create a certain number of rules for each {@link AutoModTriggerType AutoModTriggerType}. * The maximum is provided by {@link AutoModTriggerType#getMaxPerGuild()}. * * @param data * The data for the new rule * * @throws InsufficientPermissionException * If the currently logged in account does not have the {@link AutoModRuleData#getRequiredPermissions() required permissions} * @throws IllegalStateException *

    *
  • If the provided data does not have any {@link AutoModResponse} configured
  • *
  • If any of the configured {@link AutoModResponse AutoModResponses} is not supported by the {@link AutoModTriggerType}
  • *
* * @return {@link AuditableRestAction} - Type: {@link AutoModRule} */ @Nonnull @CheckReturnValue AuditableRestAction createAutoModRule(@Nonnull AutoModRuleData data); /** * Returns an {@link AutoModRuleManager}, which can be used to modify the rule for the provided id. *

The manager allows modifying multiple fields in a single request. *
You modify multiple fields in one request by chaining setters before calling {@link net.dv8tion.jda.api.requests.RestAction#queue() RestAction.queue()}. * * @throws InsufficientPermissionException * If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission. * * @return The manager instance */ @Nonnull @CheckReturnValue AutoModRuleManager modifyAutoModRuleById(@Nonnull String id); /** * Returns an {@link AutoModRuleManager}, which can be used to modify the rule for the provided id. *

The manager allows modifying multiple fields in a single request. *
You modify multiple fields in one request by chaining setters before calling {@link net.dv8tion.jda.api.requests.RestAction#queue() RestAction.queue()}. * * @throws InsufficientPermissionException * If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission. * * @return The manager instance */ @Nonnull @CheckReturnValue default AutoModRuleManager modifyAutoModRuleById(long id) { return modifyAutoModRuleById(Long.toUnsignedString(id)); } /** * Deletes the {@link AutoModRule} for the provided id. * * @param id * The id of the rule * * @throws IllegalArgumentException * If the provided id is not a valid snowflake * @throws InsufficientPermissionException * If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission * * @return {@link AuditableRestAction} - Type: {@link Void} */ @Nonnull @CheckReturnValue AuditableRestAction deleteAutoModRuleById(@Nonnull String id); /** * Deletes the {@link AutoModRule} for the provided id. * * @param id * The id of the rule * * @throws InsufficientPermissionException * If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission * * @return {@link AuditableRestAction} - Type: {@link Void} */ @Nonnull @CheckReturnValue default AuditableRestAction deleteAutoModRuleById(long id) { return deleteAutoModRuleById(Long.toUnsignedString(id)); } /** * Adds the user to this guild as a member. *
This requires an OAuth2 Access Token with the scope {@code guilds.join}. * * @param accessToken * The access token * @param user * The {@link UserSnowflake} for the member to add. * This can be a member or user instance or {@link User#fromId(long)}. * * @throws IllegalArgumentException * If the access token is blank, empty, or null, * or if the provided user reference is null or is already in this guild * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException * If the currently logged in account does not have {@link net.dv8tion.jda.api.Permission#CREATE_INSTANT_INVITE Permission.CREATE_INSTANT_INVITE} * * @return {@link MemberAction MemberAction} * * @see Discord OAuth2 Documentation * * @since 3.7.0 */ @Nonnull @CheckReturnValue MemberAction addMember(@Nonnull String accessToken, @Nonnull UserSnowflake user); /** * Whether this guild has loaded members. *
This will always be false if the {@link GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} intent is disabled. * * @return True, if members are loaded. */ boolean isLoaded(); /** * Re-apply the {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} of this session to all {@link Member Members} of this Guild. * *

Example
*

{@code
     * // Check if the members of this guild have at least 50% bots (bot collection/farm)
     * public void checkBots(Guild guild) {
     *     // Keep in mind: This requires the GUILD_MEMBERS intent which is disabled in createDefault and createLight by default
     *     guild.retrieveMembers() // Load members CompletableFuture (async and eager)
     *          .thenApply((v) -> guild.getMemberCache()) // Turn into CompletableFuture
     *          .thenAccept((members) -> {
     *              int total = members.size();
     *              // Casting to double to get a double as result of division, don't need to worry about precision with small counts like this
     *              double bots = (double) members.applyStream(stream ->
     *                  stream.map(Member::getUser)
     *                        .filter(User::isBot)
     *                        .count()); // Count bots
     *              if (bots / total > 0.5) // Check how many members are bots
     *                  System.out.println("More than 50% of members in this guild are bots");
     *          })
     *          .thenRun(guild::pruneMemberCache); // Then prune the cache
     * }
     * }
* * @see #unloadMember(long) * @see JDA#unloadUser(long) */ void pruneMemberCache(); /** * Attempts to remove the user with the provided id from the member cache. *
If you attempt to remove the {@link JDA#getSelfUser() SelfUser} this will simply return {@code false}. * *

This should be used by an implementation of {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} * as an upstream request to remove a member. For example a Least-Recently-Used (LRU) cache might use this to drop * old members if the cache capacity is reached. Or a timeout cache could use this to remove expired members. * * @param userId * The target user id * * @return True, if the cache was changed * * @see #pruneMemberCache() * @see JDA#unloadUser(long) */ boolean unloadMember(long userId); /** * The expected member count for this guild. *
If this guild is not lazy loaded this should be identical to the size returned by {@link #getMemberCache()}. * *

When {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} is disabled, this will not be updated. * * @return The expected member count for this guild */ int getMemberCount(); /** * The human readable name of the {@link net.dv8tion.jda.api.entities.Guild Guild}. *

* This value can be modified using {@link GuildManager#setName(String)}. * * @return Never-null String containing the Guild's name. */ @Nonnull String getName(); /** * The Discord hash-id of the {@link net.dv8tion.jda.api.entities.Guild Guild} icon image. * If no icon has been set, this returns {@code null}. *

* The Guild icon can be modified using {@link GuildManager#setIcon(Icon)}. * * @return Possibly-null String containing the Guild's icon hash-id. */ @Nullable String getIconId(); /** * The URL of the {@link net.dv8tion.jda.api.entities.Guild Guild} icon image. * If no icon has been set, this returns {@code null}. *

* The Guild icon can be modified using {@link GuildManager#setIcon(Icon)}. * * @return Possibly-null String containing the Guild's icon URL. */ @Nullable default String getIconUrl() { String iconId = getIconId(); return iconId == null ? null : String.format(ICON_URL, getId(), iconId, iconId.startsWith("a_") ? "gif" : "png"); } /** * Returns an {@link ImageProxy} for this guild's icon. * * @return The {@link ImageProxy} of this guild's icon * * @see #getIconUrl() */ @Nullable default ImageProxy getIcon() { final String iconUrl = getIconUrl(); return iconUrl == null ? null : new ImageProxy(iconUrl); } /** * The Features of the {@link net.dv8tion.jda.api.entities.Guild Guild}. * *

Features can be updated using {@link GuildManager#setFeatures(Collection)}. * * @return Never-null, unmodifiable Set containing all of the Guild's features. * * @see List of Features */ @Nonnull Set getFeatures(); /** * Whether the invites for this guild are paused/disabled. *
This is equivalent to {@code getFeatures().contains("INVITES_DISABLED")}. * * @return True, if invites are paused/disabled */ default boolean isInvitesDisabled() { return getFeatures().contains("INVITES_DISABLED"); } /** * The Discord hash-id of the splash image for this Guild. A Splash image is an image displayed when viewing a * Discord Guild Invite on the web or in client just before accepting or declining the invite. * If no splash has been set, this returns {@code null}. *
Splash images are VIP/Partner Guild only. *

* The Guild splash can be modified using {@link GuildManager#setSplash(Icon)}. * * @return Possibly-null String containing the Guild's splash hash-id */ @Nullable String getSplashId(); /** * The URL of the splash image for this Guild. A Splash image is an image displayed when viewing a * Discord Guild Invite on the web or in client just before accepting or declining the invite. * If no splash has been set, this returns {@code null}. *
Splash images are VIP/Partner Guild only. *

* The Guild splash can be modified using {@link GuildManager#setSplash(Icon)}. * * @return Possibly-null String containing the Guild's splash URL. */ @Nullable default String getSplashUrl() { String splashId = getSplashId(); return splashId == null ? null : String.format(SPLASH_URL, getId(), splashId); } /** * Returns an {@link ImageProxy} for this guild's splash icon. * * @return Possibly-null {@link ImageProxy} of this guild's splash icon * * @see #getSplashUrl() */ @Nullable default ImageProxy getSplash() { final String splashUrl = getSplashUrl(); return splashUrl == null ? null : new ImageProxy(splashUrl); } /** * The vanity url code for this Guild. The vanity url is the custom invite code of partnered / official / boosted Guilds. *
The returned String will be the code that can be provided to {@code discord.gg/{code}} to get the invite link. * * @return The vanity code or null * * @since 4.0.0 * * @see #getVanityUrl() */ @Nullable String getVanityCode(); /** * The vanity url for this Guild. The vanity url is the custom invite code of partnered / official / boosted Guilds. *
The returned String will be the vanity invite link to this guild. * * @return The vanity url or null * * @since 4.0.0 */ @Nullable default String getVanityUrl() { return getVanityCode() == null ? null : "https://discord.gg/" + getVanityCode(); } /** * Retrieves the Vanity Invite meta data for this guild. *
This allows you to inspect how many times the vanity invite has been used. * You can use {@link #getVanityUrl()} if you only care about the invite. * *

This action requires the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission. * *

Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by * the returned {@link RestAction RestAction} include the following: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#INVITE_CODE_INVALID INVITE_CODE_INVALID} *
    If this guild does not have a vanity invite
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS} *
    The vanity invite cannot be fetched due to a permission discrepancy
  • *
* * @throws InsufficientPermissionException * If the currently logged in account does not have {@link Permission#MANAGE_SERVER Permission.MANAGE_SERVER} * * @return {@link RestAction} - Type: {@link VanityInvite} * * @since 4.2.1 */ @Nonnull @CheckReturnValue RestAction retrieveVanityInvite(); /** * The description for this guild. *
This is displayed in the server browser below the guild name for verified guilds. * *

The description can be modified using {@link GuildManager#setDescription(String)}. * * @return The description * * @since 4.0.0 */ @Nullable String getDescription(); /** * The preferred locale for this guild. *
If the guild doesn't have the COMMUNITY feature, this returns the default. * *
Default: {@link DiscordLocale#ENGLISH_US} * * @return The preferred {@link DiscordLocale} for this guild * * @since 4.2.1 */ @Nonnull DiscordLocale getLocale(); /** * The guild banner id. *
This is shown in guilds below the guild name. * *

The banner can be modified using {@link GuildManager#setBanner(Icon)}. * * @return The guild banner id or null * * @since 4.0.0 * * @see #getBannerUrl() */ @Nullable String getBannerId(); /** * The guild banner url. *
This is shown in guilds below the guild name. * *

The banner can be modified using {@link GuildManager#setBanner(Icon)}. * * @return The guild banner url or null * * @since 4.0.0 */ @Nullable default String getBannerUrl() { String bannerId = getBannerId(); return bannerId == null ? null : String.format(BANNER_URL, getId(), bannerId, bannerId.startsWith("a_") ? "gif" : "png"); } /** * Returns an {@link ImageProxy} for this guild's banner image. * * @return Possibly-null {@link ImageProxy} of this guild's banner image * * @see #getBannerUrl() */ @Nullable default ImageProxy getBanner() { final String bannerUrl = getBannerUrl(); return bannerUrl == null ? null : new ImageProxy(bannerUrl); } /** * The boost tier for this guild. *
Each tier unlocks new perks for a guild that can be seen in the {@link #getFeatures() features}. * * @return The boost tier. * * @since 4.0.0 */ @Nonnull BoostTier getBoostTier(); /** * The amount of boosts this server currently has. * * @return The boost count * * @since 4.0.0 */ int getBoostCount(); /** * Sorted list of {@link net.dv8tion.jda.api.entities.Member Members} that boost this guild. *
The list is sorted by {@link net.dv8tion.jda.api.entities.Member#getTimeBoosted()} ascending. * This means the first element will be the member who has been boosting for the longest time. * *

This will only check cached members! *
See {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} * * @return Possibly-immutable list of members who boost this guild */ @Nonnull List getBoosters(); /** * The maximum bitrate that can be applied to a voice channel in this guild. *
This depends on the features of this guild that can be unlocked for partners or through boosting. * * @return The maximum bitrate * * @since 4.0.0 */ default int getMaxBitrate() { int maxBitrate = getFeatures().contains("VIP_REGIONS") ? 384000 : 96000; return Math.max(maxBitrate, getBoostTier().getMaxBitrate()); } /** * Returns the maximum size for files that can be uploaded to this Guild. * This returns 8 MiB for Guilds without a Boost Tier or Guilds with Boost Tier 1, 50 MiB for Guilds with Boost Tier 2 and 100 MiB for Guilds with Boost Tier 3. * * @return The maximum size for files that can be uploaded to this Guild * * @since 4.2.0 */ default long getMaxFileSize() { return getBoostTier().getMaxFileSize(); } /** * The maximum amount of custom emojis a guild can have based on the guilds boost tier. * * @return The maximum amount of custom emojis */ default int getMaxEmojis() { int max = getFeatures().contains("MORE_EMOJI") ? 200 : 50; return Math.max(max, getBoostTier().getMaxEmojis()); } /** * The maximum amount of members that can join this guild. * * @return The maximum amount of members * * @since 4.0.0 * * @see #retrieveMetaData() */ int getMaxMembers(); /** * The maximum amount of connected members this guild can have at a time. *
This includes members that are invisible but still connected to discord. * If too many members are online the guild will become unavailable for others. * * @return The maximum amount of connected members this guild can have * * @since 4.0.0 * * @see #retrieveMetaData() */ int getMaxPresences(); /** * Loads {@link MetaData} for this guild instance. * * @return {@link RestAction} - Type: {@link MetaData} * * @since 4.2.0 */ @Nonnull @CheckReturnValue RestAction retrieveMetaData(); /** * Provides the {@link VoiceChannel VoiceChannel} that has been set as the channel * which {@link net.dv8tion.jda.api.entities.Member Members} will be moved to after they have been inactive in a * {@link VoiceChannel VoiceChannel} for longer than {@link #getAfkTimeout()}. *
If no channel has been set as the AFK channel, this returns {@code null}. *

* This value can be modified using {@link GuildManager#setAfkChannel(VoiceChannel)}. * * @return Possibly-null {@link VoiceChannel VoiceChannel} that is the AFK Channel. */ @Nullable VoiceChannel getAfkChannel(); /** * Provides the {@link TextChannel TextChannel} that has been set as the channel * which newly joined {@link net.dv8tion.jda.api.entities.Member Members} will be announced in. *
If no channel has been set as the system channel, this returns {@code null}. *

* This value can be modified using {@link GuildManager#setSystemChannel(TextChannel)}. * * @return Possibly-null {@link TextChannel TextChannel} that is the system Channel. */ @Nullable TextChannel getSystemChannel(); /** * Provides the {@link TextChannel TextChannel} that lists the rules of the guild. *
If this guild doesn't have the COMMUNITY {@link #getFeatures() feature}, this returns {@code null}. * * @return Possibly-null {@link TextChannel TextChannel} that is the rules channel * * @see #getFeatures() */ @Nullable TextChannel getRulesChannel(); /** * Provides the {@link TextChannel TextChannel} that receives community updates. *
If this guild doesn't have the COMMUNITY {@link #getFeatures() feature}, this returns {@code null}. * * @return Possibly-null {@link TextChannel TextChannel} that is the community updates channel * * @see #getFeatures() */ @Nullable TextChannel getCommunityUpdatesChannel(); /** * The {@link net.dv8tion.jda.api.entities.Member Member} object for the owner of this Guild. *
This is null when the owner is no longer in this guild or not yet loaded (lazy loading). * Sometimes owners of guilds delete their account or get banned by Discord. * *

If lazy-loading is used it is recommended to use {@link #retrieveOwner()} instead. * *

Ownership can be transferred using {@link net.dv8tion.jda.api.entities.Guild#transferOwnership(Member)}. * *

This only works when the member was added to cache. Lazy loading might load this later. *
See {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} * * @return Possibly-null Member object for the Guild owner. * * @see #getOwnerIdLong() * @see #retrieveOwner() */ @Nullable Member getOwner(); /** * The ID for the current owner of this guild. *
This is useful for debugging purposes or as a shortcut. * * @return The ID for the current owner * * @see #getOwner() */ long getOwnerIdLong(); /** * The ID for the current owner of this guild. *
This is useful for debugging purposes or as a shortcut. * * @return The ID for the current owner * * @see #getOwner() */ @Nonnull default String getOwnerId() { return Long.toUnsignedString(getOwnerIdLong()); } /** * The {@link net.dv8tion.jda.api.entities.Guild.Timeout Timeout} set for this Guild representing the amount of time * that must pass for a Member to have had no activity in a {@link VoiceChannel VoiceChannel} * to be considered AFK. If {@link #getAfkChannel()} is not {@code null} (thus an AFK channel has been set) then Member * will be automatically moved to the AFK channel after they have been inactive for longer than the returned Timeout. *
Default is {@link Timeout#SECONDS_300 300 seconds (5 minutes)}. *

* This value can be modified using {@link GuildManager#setAfkTimeout(net.dv8tion.jda.api.entities.Guild.Timeout)}. * * @return The {@link net.dv8tion.jda.api.entities.Guild.Timeout Timeout} set for this Guild. */ @Nonnull Timeout getAfkTimeout(); /** * Used to determine if the provided {@link UserSnowflake} is a member of this Guild. * *

This will only check cached members! If the cache is not loaded (see {@link #isLoaded()}), this may return false despite the user being a member. * This is false when {@link #getMember(UserSnowflake)} returns {@code null}. * * @param user * The user to check * * @return True - if this user is present and cached in this guild */ boolean isMember(@Nonnull UserSnowflake user); /** * Gets the {@link net.dv8tion.jda.api.entities.Member Member} object of the currently logged in account in this guild. *
This is basically {@link net.dv8tion.jda.api.JDA#getSelfUser()} being provided to {@link #getMember(UserSnowflake)}. * * @return The Member object of the currently logged in account. */ @Nonnull Member getSelfMember(); /** * Returns the NSFW Level that this guild is classified with. *
For a short description of the different values, see {@link net.dv8tion.jda.api.entities.Guild.NSFWLevel NSFWLevel}. *

* This value can only be modified by Discord after reviewing the Guild. * * @return The NSFWLevel of this guild. */ @Nonnull NSFWLevel getNSFWLevel(); /** * Gets the Guild specific {@link net.dv8tion.jda.api.entities.Member Member} object for the provided * {@link UserSnowflake}. *
If the user is not in this guild or currently uncached, {@code null} is returned. * *

This will only check cached members! * * @param user * The {@link UserSnowflake} for the member to get. * This can be a member or user instance or {@link User#fromId(long)}. * * @throws java.lang.IllegalArgumentException * If the provided user is null * * @return Possibly-null {@link net.dv8tion.jda.api.entities.Member Member} for the related {@link net.dv8tion.jda.api.entities.User User}. * * @see #retrieveMember(UserSnowflake) */ @Nullable Member getMember(@Nonnull UserSnowflake user); /** * Gets a {@link net.dv8tion.jda.api.entities.Member Member} object via the id of the user. The id relates to * {@link net.dv8tion.jda.api.entities.User#getId()}, and this method is similar to {@link JDA#getUserById(String)} *
This is more efficient that using {@link JDA#getUserById(String)} and {@link #getMember(UserSnowflake)}. *
If no Member in this Guild has the {@code userId} provided, this returns {@code null}. * *

This will only check cached members! * * @param userId * The Discord id of the User for which a Member object is requested. * * @throws java.lang.NumberFormatException * If the provided {@code id} cannot be parsed by {@link Long#parseLong(String)} * * @return Possibly-null {@link net.dv8tion.jda.api.entities.Member Member} with the related {@code userId}. * * @see #retrieveMemberById(String) */ @Nullable default Member getMemberById(@Nonnull String userId) { return getMemberCache().getElementById(userId); } /** * Gets a {@link net.dv8tion.jda.api.entities.Member Member} object via the id of the user. The id relates to * {@link net.dv8tion.jda.api.entities.User#getIdLong()}, and this method is similar to {@link JDA#getUserById(long)} *
This is more efficient that using {@link JDA#getUserById(long)} and {@link #getMember(UserSnowflake)}. *
If no Member in this Guild has the {@code userId} provided, this returns {@code null}. * *

This will only check cached members! *
See {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} * * @param userId * The Discord id of the User for which a Member object is requested. * * @return Possibly-null {@link net.dv8tion.jda.api.entities.Member Member} with the related {@code userId}. * * @see #retrieveMemberById(long) */ @Nullable default Member getMemberById(long userId) { return getMemberCache().getElementById(userId); } /** * Searches for a {@link net.dv8tion.jda.api.entities.Member} that has the matching Discord Tag. *
Format has to be in the form {@code Username#Discriminator} where the * username must be between 2 and 32 characters (inclusive) matching the exact casing and the discriminator * must be exactly 4 digits. *
This does not check the {@link net.dv8tion.jda.api.entities.Member#getNickname() nickname} of the member * but the username. * *

This will only check cached members! *
See {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} * *

This only checks users that are in this guild. If a user exists * with the tag that is not available in the {@link #getMemberCache() Member-Cache} it will not be detected. *
Currently Discord does not offer a way to retrieve a user by their discord tag. * * @param tag * The Discord Tag in the format {@code Username#Discriminator} * * @throws java.lang.IllegalArgumentException * If the provided tag is null or not in the described format * * @return The {@link net.dv8tion.jda.api.entities.Member} for the discord tag or null if no member has the provided tag * * @see net.dv8tion.jda.api.JDA#getUserByTag(String) * * @deprecated This will become obsolete in the future. * Discriminators are being phased out and replaced by globally unique usernames. * For more information, see New Usernames & Display Names. */ @Nullable @Deprecated @ForRemoval default Member getMemberByTag(@Nonnull String tag) { User user = getJDA().getUserByTag(tag); return user == null ? null : getMember(user); } /** * Searches for a {@link net.dv8tion.jda.api.entities.Member} that has the matching Discord Tag. *
Format has to be in the form {@code Username#Discriminator} where the * username must be between 2 and 32 characters (inclusive) matching the exact casing and the discriminator * must be exactly 4 digits. *
This does not check the {@link net.dv8tion.jda.api.entities.Member#getNickname() nickname} of the member * but the username. * *

This will only check cached members! *
See {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} * *

This only checks users that are in this guild. If a user exists * with the tag that is not available in the {@link #getMemberCache() Member-Cache} it will not be detected. *
Currently Discord does not offer a way to retrieve a user by their discord tag. * * @param username * The name of the user * @param discriminator * The discriminator of the user * * @throws java.lang.IllegalArgumentException * If the provided arguments are null or not in the described format * * @return The {@link net.dv8tion.jda.api.entities.Member} for the discord tag or null if no member has the provided tag * * @see #getMemberByTag(String) * * @deprecated This will become obsolete in the future. * Discriminators are being phased out and replaced by globally unique usernames. * For more information, see New Usernames & Display Names. */ @Nullable @Deprecated @ForRemoval default Member getMemberByTag(@Nonnull String username, @Nonnull String discriminator) { User user = getJDA().getUserByTag(username, discriminator); return user == null ? null : getMember(user); } /** * A list of all {@link net.dv8tion.jda.api.entities.Member Members} in this Guild. *
The Members are not provided in any particular order. * *

This will only check cached members! *
See {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} * *

This copies the backing store into a list. This means every call * creates a new list with O(n) complexity. It is recommended to store this into * a local variable or use {@link #getMemberCache()} and use its more efficient * versions of handling these values. * * @return Immutable list of all cached members in this Guild. * * @see #loadMembers() */ @Nonnull default List getMembers() { return getMemberCache().asList(); } /** * Gets a list of all {@link net.dv8tion.jda.api.entities.Member Members} who have the same name as the one provided. *
This compares against {@link net.dv8tion.jda.api.entities.Member#getUser()}{@link net.dv8tion.jda.api.entities.User#getName() .getName()} *
If there are no {@link net.dv8tion.jda.api.entities.Member Members} with the provided name, then this returns an empty list. * *

This will only check cached members! *
See {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} * * @param name * The name used to filter the returned Members. * @param ignoreCase * Determines if the comparison ignores case when comparing. True - case insensitive. * * @throws IllegalArgumentException * If the provided name is null * * @return Possibly-empty immutable list of all Members with the same name as the name provided. * * @see #retrieveMembersByPrefix(String, int) * * @incubating This will be replaced in the future when the rollout of globally unique usernames has been completed. */ @Nonnull @Incubating default List getMembersByName(@Nonnull String name, boolean ignoreCase) { return getMemberCache().getElementsByUsername(name, ignoreCase); } /** * Gets a list of all {@link net.dv8tion.jda.api.entities.Member Members} who have the same nickname as the one provided. *
This compares against {@link Member#getNickname()}. If a Member does not have a nickname, the comparison results as false. *
If there are no {@link net.dv8tion.jda.api.entities.Member Members} with the provided name, then this returns an empty list. * *

This will only check cached members! *
See {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} * * @param nickname * The nickname used to filter the returned Members. * @param ignoreCase * Determines if the comparison ignores case when comparing. True - case insensitive. * * @return Possibly-empty immutable list of all Members with the same nickname as the nickname provided. * * @see #retrieveMembersByPrefix(String, int) */ @Nonnull default List getMembersByNickname(@Nullable String nickname, boolean ignoreCase) { return getMemberCache().getElementsByNickname(nickname, ignoreCase); } /** * Gets a list of all {@link net.dv8tion.jda.api.entities.Member Members} who have the same effective name as the one provided. *
This compares against {@link net.dv8tion.jda.api.entities.Member#getEffectiveName()}. *
If there are no {@link net.dv8tion.jda.api.entities.Member Members} with the provided name, then this returns an empty list. * *

This will only check cached members! *
See {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} * * @param name * The name used to filter the returned Members. * @param ignoreCase * Determines if the comparison ignores case when comparing. True - case insensitive. * * @throws IllegalArgumentException * If the provided name is null * * @return Possibly-empty immutable list of all Members with the same effective name as the name provided. * * @see #retrieveMembersByPrefix(String, int) */ @Nonnull default List getMembersByEffectiveName(@Nonnull String name, boolean ignoreCase) { return getMemberCache().getElementsByName(name, ignoreCase); } /** * Gets a list of {@link net.dv8tion.jda.api.entities.Member Members} that have all {@link Role Roles} provided. *
If there are no {@link net.dv8tion.jda.api.entities.Member Members} with all provided roles, then this returns an empty list. * *

This will only check cached members! *
See {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} * * @param roles * The {@link Role Roles} that a {@link net.dv8tion.jda.api.entities.Member Member} * must have to be included in the returned list. * * @throws java.lang.IllegalArgumentException * If a provided {@link Role Role} is from a different guild or null. * * @return Possibly-empty immutable list of Members with all provided Roles. * * @see #findMembersWithRoles(Role...) */ @Nonnull default List getMembersWithRoles(@Nonnull Role... roles) { Checks.notNull(roles, "Roles"); return getMembersWithRoles(Arrays.asList(roles)); } /** * Gets a list of {@link net.dv8tion.jda.api.entities.Member Members} that have all provided {@link Role Roles}. *
If there are no {@link net.dv8tion.jda.api.entities.Member Members} with all provided roles, then this returns an empty list. * *

This will only check cached members! *
See {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} * * @param roles * The {@link Role Roles} that a {@link net.dv8tion.jda.api.entities.Member Member} * must have to be included in the returned list. * * @throws java.lang.IllegalArgumentException * If a provided {@link Role Role} is from a different guild or null. * * @return Possibly-empty immutable list of Members with all provided Roles. * * @see #findMembersWithRoles(Collection) */ @Nonnull default List getMembersWithRoles(@Nonnull Collection roles) { Checks.noneNull(roles, "Roles"); for (Role role : roles) Checks.check(this.equals(role.getGuild()), "All roles must be from the same guild!"); return getMemberCache().getElementsWithRoles(roles); } /** * {@link net.dv8tion.jda.api.utils.cache.MemberCacheView MemberCacheView} for all cached * {@link net.dv8tion.jda.api.entities.Member Members} of this Guild. * *

This will only provide cached members! *
See {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} * * @return {@link net.dv8tion.jda.api.utils.cache.MemberCacheView MemberCacheView} * * @see #loadMembers() */ @Nonnull MemberCacheView getMemberCache(); /** * Sorted {@link SnowflakeCacheView} of * all cached {@link ScheduledEvent ScheduledEvents} of this Guild. *
Scheduled events are sorted by their start time, and events that start at the same time * are sorted by their snowflake ID. * *

This requires {@link CacheFlag#SCHEDULED_EVENTS} to be enabled. * * @return {@link SortedSnowflakeCacheView} */ @Nonnull SortedSnowflakeCacheView getScheduledEventCache(); /** * Gets a list of all {@link ScheduledEvent ScheduledEvents} in this Guild that have the same * name as the one provided. *
If there are no {@link ScheduledEvent ScheduledEvents} with the provided name, * then this returns an empty list. * *

This requires {@link CacheFlag#SCHEDULED_EVENTS} to be enabled. * * @param name * The name used to filter the returned {@link ScheduledEvent} objects. * @param ignoreCase * Determines if the comparison ignores case when comparing. True - case insensitive. * * @throws java.lang.IllegalArgumentException * If the name is blank, empty or {@code null} * * @return Possibly-empty immutable list of all ScheduledEvent names that match the provided name. */ @Nonnull default List getScheduledEventsByName(@Nonnull String name, boolean ignoreCase) { return getScheduledEventCache().getElementsByName(name, ignoreCase); } /** * Gets a {@link ScheduledEvent} from this guild that has the same id as the * one provided. This method is similar to {@link JDA#getScheduledEventById(String)}, but it only * checks this specific Guild for a scheduled event. *
If there is no {@link ScheduledEvent} with an id that matches the provided * one, then this returns {@code null}. * *

This requires {@link CacheFlag#SCHEDULED_EVENTS} to be enabled. * * @param id * The id of the {@link ScheduledEvent}. * * @throws java.lang.NumberFormatException * If the provided {@code id} cannot be parsed by {@link Long#parseLong(String)} * * @return Possibly-null {@link ScheduledEvent} with matching id. */ @Nullable default ScheduledEvent getScheduledEventById(@Nonnull String id) { return getScheduledEventCache().getElementById(id); } /** * Gets a {@link ScheduledEvent} from this guild that has the same id as the * one provided. This method is similar to {@link JDA#getScheduledEventById(long)}, but it only * checks this specific Guild for a scheduled event. *
If there is no {@link ScheduledEvent} with an id that matches the provided * one, then this returns {@code null}. * *

This requires {@link CacheFlag#SCHEDULED_EVENTS} to be enabled. * * @param id * The id of the {@link ScheduledEvent}. * * @return Possibly-null {@link ScheduledEvent} with matching id. */ @Nullable default ScheduledEvent getScheduledEventById(long id) { return getScheduledEventCache().getElementById(id); } /** * Gets all {@link ScheduledEvent ScheduledEvents} in this guild. *
Scheduled events are sorted by their start time, and events that start at the same time * are sorted by their snowflake ID. * *

This copies the backing store into a list. This means every call * creates a new list with O(n) complexity. It is recommended to store this into * a local variable or use {@link #getScheduledEventCache()} and use its more efficient * versions of handling these values. * *

This requires {@link CacheFlag#SCHEDULED_EVENTS} to be enabled. * * @return Possibly-empty immutable List of {@link ScheduledEvent ScheduledEvents}. */ @Nonnull default List getScheduledEvents() { return getScheduledEventCache().asList(); } @Nonnull @Override SortedSnowflakeCacheView getStageChannelCache(); @Nonnull @Override SortedSnowflakeCacheView getThreadChannelCache(); @Nonnull @Override SortedSnowflakeCacheView getCategoryCache(); @Nonnull @Override SortedSnowflakeCacheView getTextChannelCache(); @Nonnull @Override SortedSnowflakeCacheView getNewsChannelCache(); @Nonnull @Override SortedSnowflakeCacheView getVoiceChannelCache(); @Nonnull @Override SortedSnowflakeCacheView getForumChannelCache(); /** * Populated list of {@link GuildChannel channels} for this guild. *
This includes all types of channels, except for threads. *
This includes hidden channels by default, * you can use {@link #getChannels(boolean) getChannels(false)} to exclude hidden channels. * *

The returned list is ordered in the same fashion as it would be by the official discord client. *

    *
  1. TextChannel, ForumChannel, and NewsChannel without parent
  2. *
  3. VoiceChannel and StageChannel without parent
  4. *
  5. Categories *
      *
    1. TextChannel, ForumChannel, and NewsChannel with category as parent
    2. *
    3. VoiceChannel and StageChannel with category as parent
    4. *
    *
  6. *
* * @return Immutable list of channels for this guild * * @see #getChannels(boolean) */ @Nonnull default List getChannels() { return getChannels(true); } /** * Populated list of {@link GuildChannel channels} for this guild. *
This includes all types of channels, except for threads. * *

The returned list is ordered in the same fashion as it would be by the official discord client. *

    *
  1. TextChannel, ForumChannel, and NewsChannel without parent
  2. *
  3. VoiceChannel and StageChannel without parent
  4. *
  5. Categories *
      *
    1. TextChannel, ForumChannel, and NewsChannel with category as parent
    2. *
    3. VoiceChannel and StageChannel with category as parent
    4. *
    *
  6. *
* * @param includeHidden * Whether to include channels with denied {@link Permission#VIEW_CHANNEL View Channel Permission} * * @return Immutable list of channels for this guild * * @see #getChannels() */ @Nonnull List getChannels(boolean includeHidden); /** * Gets a {@link Role Role} from this guild that has the same id as the * one provided. *
If there is no {@link Role Role} with an id that matches the provided * one, then this returns {@code null}. * * @param id * The id of the {@link Role Role}. * * @throws java.lang.NumberFormatException * If the provided {@code id} cannot be parsed by {@link Long#parseLong(String)} * * @return Possibly-null {@link Role Role} with matching id. */ @Nullable default Role getRoleById(@Nonnull String id) { return getRoleCache().getElementById(id); } /** * Gets a {@link Role Role} from this guild that has the same id as the * one provided. *
If there is no {@link Role Role} with an id that matches the provided * one, then this returns {@code null}. * * @param id * The id of the {@link Role Role}. * * @return Possibly-null {@link Role Role} with matching id. */ @Nullable default Role getRoleById(long id) { return getRoleCache().getElementById(id); } /** * Gets all {@link Role Roles} in this {@link net.dv8tion.jda.api.entities.Guild Guild}. *
The roles returned will be sorted according to their position. The highest role being at index 0 * and the lowest at the last index. * *

This copies the backing store into a list. This means every call * creates a new list with O(n) complexity. It is recommended to store this into * a local variable or use {@link #getRoleCache()} and use its more efficient * versions of handling these values. * * @return An immutable List of {@link Role Roles}. */ @Nonnull default List getRoles() { return getRoleCache().asList(); } /** * Gets a list of all {@link Role Roles} in this Guild that have the same * name as the one provided. *
If there are no {@link Role Roles} with the provided name, then this returns an empty list. * * @param name * The name used to filter the returned {@link Role Roles}. * @param ignoreCase * Determines if the comparison ignores case when comparing. True - case insensitive. * * @return Possibly-empty immutable list of all Role names that match the provided name. */ @Nonnull default List getRolesByName(@Nonnull String name, boolean ignoreCase) { return getRoleCache().getElementsByName(name, ignoreCase); } /** * Looks up a role which is the integration role for a bot. *
These roles are created when the bot requested a list of permission in the authorization URL. * *

To check whether a role is a bot role you can use {@code role.getTags().isBot()} and you can use * {@link Role.RoleTags#getBotIdLong()} to check which bot it applies to. * *

This requires {@link net.dv8tion.jda.api.utils.cache.CacheFlag#ROLE_TAGS CacheFlag.ROLE_TAGS} to be enabled. * See {@link net.dv8tion.jda.api.JDABuilder#enableCache(CacheFlag, CacheFlag...) JDABuilder.enableCache(...)}. * * @param userId * The user id of the bot * * @return The bot role, or null if no role matches */ @Nullable default Role getRoleByBot(long userId) { return getRoleCache().applyStream(stream -> stream.filter(role -> role.getTags().getBotIdLong() == userId) .findFirst() .orElse(null) ); } /** * Looks up a role which is the integration role for a bot. *
These roles are created when the bot requested a list of permission in the authorization URL. * *

To check whether a role is a bot role you can use {@code role.getTags().isBot()} and you can use * {@link Role.RoleTags#getBotIdLong()} to check which bot it applies to. * *

This requires {@link net.dv8tion.jda.api.utils.cache.CacheFlag#ROLE_TAGS CacheFlag.ROLE_TAGS} to be enabled. * See {@link net.dv8tion.jda.api.JDABuilder#enableCache(CacheFlag, CacheFlag...) JDABuilder.enableCache(...)}. * * @param userId * The user id of the bot * * @throws IllegalArgumentException * If the userId is null or not a valid snowflake * * @return The bot role, or null if no role matches */ @Nullable default Role getRoleByBot(@Nonnull String userId) { return getRoleByBot(MiscUtil.parseSnowflake(userId)); } /** * Looks up a role which is the integration role for a bot. *
These roles are created when the bot requested a list of permission in the authorization URL. * *

To check whether a role is a bot role you can use {@code role.getTags().isBot()} and you can use * {@link Role.RoleTags#getBotIdLong()} to check which bot it applies to. * *

This requires {@link net.dv8tion.jda.api.utils.cache.CacheFlag#ROLE_TAGS CacheFlag.ROLE_TAGS} to be enabled. * See {@link net.dv8tion.jda.api.JDABuilder#enableCache(CacheFlag, CacheFlag...) JDABuilder.enableCache(...)}. * * @param user * The bot user * * @throws IllegalArgumentException * If null is provided * * @return The bot role, or null if no role matches */ @Nullable default Role getRoleByBot(@Nonnull User user) { Checks.notNull(user, "User"); return getRoleByBot(user.getIdLong()); } /** * Looks up the role which is the integration role for the currently connected bot (self-user). *
These roles are created when the bot requested a list of permission in the authorization URL. * *

To check whether a role is a bot role you can use {@code role.getTags().isBot()} and you can use * {@link Role.RoleTags#getBotIdLong()} to check which bot it applies to. * *

This requires {@link net.dv8tion.jda.api.utils.cache.CacheFlag#ROLE_TAGS CacheFlag.ROLE_TAGS} to be enabled. * See {@link net.dv8tion.jda.api.JDABuilder#enableCache(CacheFlag, CacheFlag...) JDABuilder.enableCache(...)}. * * @return The bot role, or null if no role matches */ @Nullable default Role getBotRole() { return getRoleByBot(getJDA().getSelfUser()); } /** * Looks up the role which is the booster role of this guild. *
These roles are created when the first user boosts this guild. * *

To check whether a role is a booster role you can use {@code role.getTags().isBoost()}. * *

This requires {@link net.dv8tion.jda.api.utils.cache.CacheFlag#ROLE_TAGS CacheFlag.ROLE_TAGS} to be enabled. * See {@link net.dv8tion.jda.api.JDABuilder#enableCache(CacheFlag, CacheFlag...) JDABuilder.enableCache(...)}. * * @return The boost role, or null if no role matches */ @Nullable default Role getBoostRole() { return getRoleCache().applyStream(stream -> stream.filter(role -> role.getTags().isBoost()) .findFirst() .orElse(null) ); } /** * Sorted {@link net.dv8tion.jda.api.utils.cache.SnowflakeCacheView SnowflakeCacheView} of * all cached {@link Role Roles} of this Guild. *
Roles are sorted according to their position. * * @return {@link net.dv8tion.jda.api.utils.cache.SortedSnowflakeCacheView SortedSnowflakeCacheView} */ @Nonnull SortedSnowflakeCacheView getRoleCache(); /** * Gets a {@link RichCustomEmoji} from this guild that has the same id as the * one provided. *
If there is no {@link RichCustomEmoji} with an id that matches the provided * one, then this returns {@code null}. * *

Unicode emojis are not included as {@link RichCustomEmoji}! * *

This requires the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#EMOJI CacheFlag.EMOJI} to be enabled! * * @param id * the emoji id * * @throws java.lang.NumberFormatException * If the provided {@code id} cannot be parsed by {@link Long#parseLong(String)} * * @return An Emoji matching the specified id * * @see #retrieveEmojiById(String) */ @Nullable default RichCustomEmoji getEmojiById(@Nonnull String id) { return getEmojiCache().getElementById(id); } /** * Gets an {@link RichCustomEmoji} from this guild that has the same id as the * one provided. *
If there is no {@link RichCustomEmoji} with an id that matches the provided * one, then this returns {@code null}. * *

Unicode emojis are not included as {@link RichCustomEmoji}! * *

This requires the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#EMOJI CacheFlag.EMOJI} to be enabled! * * @param id * the emoji id * * @return An emoji matching the specified id * * @see #retrieveEmojiById(long) */ @Nullable default RichCustomEmoji getEmojiById(long id) { return getEmojiCache().getElementById(id); } /** * Gets all {@link RichCustomEmoji Custom Emojis} belonging to this {@link net.dv8tion.jda.api.entities.Guild Guild}. *
Emojis are not ordered in any specific way in the returned list. * *

Unicode emojis are not included as {@link RichCustomEmoji}! * *

This copies the backing store into a list. This means every call * creates a new list with O(n) complexity. It is recommended to store this into * a local variable or use {@link #getEmojiCache()} and use its more efficient * versions of handling these values. * *

This requires the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#EMOJI CacheFlag.EMOJI} to be enabled! * * @return An immutable List of {@link RichCustomEmoji Custom Emojis}. * * @see #retrieveEmojis() */ @Nonnull default List getEmojis() { return getEmojiCache().asList(); } /** * Gets a list of all {@link RichCustomEmoji Custom Emojis} in this Guild that have the same * name as the one provided. *
If there are no {@link RichCustomEmoji Emojis} with the provided name, then this returns an empty list. * *

Unicode emojis are not included as {@link RichCustomEmoji}! * *

This requires the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#EMOJI CacheFlag.EMOJI} to be enabled! * * @param name * The name used to filter the returned {@link RichCustomEmoji Emojis}. Without colons. * @param ignoreCase * Determines if the comparison ignores case when comparing. True - case insensitive. * * @return Possibly-empty immutable list of all Emojis that match the provided name. */ @Nonnull default List getEmojisByName(@Nonnull String name, boolean ignoreCase) { return getEmojiCache().getElementsByName(name, ignoreCase); } /** * {@link net.dv8tion.jda.api.utils.cache.SnowflakeCacheView SnowflakeCacheView} of * all cached {@link RichCustomEmoji Custom Emojis} of this Guild. *
This will be empty if {@link net.dv8tion.jda.api.utils.cache.CacheFlag#EMOJI} is disabled. * *

This requires the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#EMOJI CacheFlag.EMOJI} to be enabled! * * @return {@link net.dv8tion.jda.api.utils.cache.SnowflakeCacheView SnowflakeCacheView} * * @see #retrieveEmojis() */ @Nonnull SnowflakeCacheView getEmojiCache(); /** * Gets a {@link net.dv8tion.jda.api.entities.sticker.GuildSticker GuildSticker} from this guild that has the same id as the * one provided. *
If there is no {@link net.dv8tion.jda.api.entities.sticker.GuildSticker GuildSticker} with an id that matches the provided * one, then this returns {@code null}. * *

This requires the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#STICKER CacheFlag.STICKER} to be enabled! * * @param id * the sticker id * * @throws java.lang.NumberFormatException * If the provided {@code id} cannot be parsed by {@link Long#parseLong(String)} * * @return A Sticker matching the specified id * * @see #retrieveSticker(StickerSnowflake) */ @Nullable default GuildSticker getStickerById(@Nonnull String id) { return getStickerCache().getElementById(id); } /** * Gets a {@link net.dv8tion.jda.api.entities.sticker.GuildSticker GuildSticker} from this guild that has the same id as the * one provided. *
If there is no {@link net.dv8tion.jda.api.entities.sticker.GuildSticker GuildSticker} with an id that matches the provided * one, then this returns {@code null}. * *

This requires the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#STICKER CacheFlag.STICKER} to be enabled! * * @param id * the sticker id * * @return A Sticker matching the specified id * * @see #retrieveSticker(StickerSnowflake) */ @Nullable default GuildSticker getStickerById(long id) { return getStickerCache().getElementById(id); } /** * Gets all custom {@link net.dv8tion.jda.api.entities.sticker.GuildSticker GuildStickers} belonging to this {@link net.dv8tion.jda.api.entities.Guild Guild}. *
GuildStickers are not ordered in any specific way in the returned list. * *

This copies the backing store into a list. This means every call * creates a new list with O(n) complexity. It is recommended to store this into * a local variable or use {@link #getStickerCache()} and use its more efficient * versions of handling these values. * *

This requires the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#STICKER CacheFlag.STICKER} to be enabled! * * @return An immutable List of {@link net.dv8tion.jda.api.entities.sticker.GuildSticker GuildStickers}. * * @see #retrieveStickers() */ @Nonnull default List getStickers() { return getStickerCache().asList(); } /** * Gets a list of all {@link net.dv8tion.jda.api.entities.sticker.GuildSticker GuildStickers} in this Guild that have the same * name as the one provided. *
If there are no {@link net.dv8tion.jda.api.entities.sticker.GuildSticker GuildStickers} with the provided name, then this returns an empty list. * *

This requires the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#STICKER CacheFlag.STICKER} to be enabled! * * @param name * The name used to filter the returned {@link net.dv8tion.jda.api.entities.sticker.GuildSticker GuildStickers}. Without colons. * @param ignoreCase * Determines if the comparison ignores case when comparing. True - case insensitive. * * @return Possibly-empty immutable list of all Stickers that match the provided name. */ @Nonnull default List getStickersByName(@Nonnull String name, boolean ignoreCase) { return getStickerCache().getElementsByName(name, ignoreCase); } /** * {@link net.dv8tion.jda.api.utils.cache.SnowflakeCacheView SnowflakeCacheView} of * all cached {@link net.dv8tion.jda.api.entities.sticker.GuildSticker GuildStickers} of this Guild. *
This will be empty if {@link net.dv8tion.jda.api.utils.cache.CacheFlag#STICKER} is disabled. * *

This requires the {@link net.dv8tion.jda.api.utils.cache.CacheFlag#STICKER CacheFlag.STICKER} to be enabled! * * @return {@link net.dv8tion.jda.api.utils.cache.SnowflakeCacheView SnowflakeCacheView} * * @see #retrieveStickers() */ @Nonnull SnowflakeCacheView getStickerCache(); /** * Retrieves an immutable list of Custom Emojis together with their respective creators. * *

Note that {@link RichCustomEmoji#getOwner()} is only available if the currently * logged in account has {@link net.dv8tion.jda.api.Permission#MANAGE_GUILD_EXPRESSIONS Permission.MANAGE_GUILD_EXPRESSIONS}. * * @return {@link RestAction RestAction} - Type: List of {@link RichCustomEmoji} */ @Nonnull @CheckReturnValue RestAction> retrieveEmojis(); /** * Retrieves a custom emoji together with its respective creator. *
This does not include unicode emoji. * *

Note that {@link RichCustomEmoji#getOwner()} is only available if the currently * logged in account has {@link net.dv8tion.jda.api.Permission#MANAGE_GUILD_EXPRESSIONS Permission.MANAGE_GUILD_EXPRESSIONS}. * *

Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by * the returned {@link RestAction RestAction} include the following: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_EMOJI UNKNOWN_EMOJI} *
    If the provided id does not correspond to an emoji in this guild
  • *
* * @param id * The emoji id * * @throws IllegalArgumentException * If the provided id is not a valid snowflake * * @return {@link RestAction RestAction} - Type: {@link RichCustomEmoji} */ @Nonnull @CheckReturnValue RestAction retrieveEmojiById(@Nonnull String id); /** * Retrieves a Custom Emoji together with its respective creator. * *

Note that {@link RichCustomEmoji#getOwner()} is only available if the currently * logged in account has {@link net.dv8tion.jda.api.Permission#MANAGE_GUILD_EXPRESSIONS Permission.MANAGE_GUILD_EXPRESSIONS}. * *

Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by * the returned {@link RestAction RestAction} include the following: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_EMOJI UNKNOWN_EMOJI} *
    If the provided id does not correspond to an emoji in this guild
  • *
* * @param id * The emoji id * * @return {@link RestAction RestAction} - Type: {@link RichCustomEmoji} */ @Nonnull @CheckReturnValue default RestAction retrieveEmojiById(long id) { return retrieveEmojiById(Long.toUnsignedString(id)); } /** * Retrieves a custom emoji together with its respective creator. * *

Note that {@link RichCustomEmoji#getOwner()} is only available if the currently * logged in account has {@link net.dv8tion.jda.api.Permission#MANAGE_GUILD_EXPRESSIONS Permission.MANAGE_GUILD_EXPRESSIONS}. * *

Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by * the returned {@link RestAction RestAction} include the following: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_EMOJI UNKNOWN_EMOJI} *
    If the provided emoji does not correspond to an emoji in this guild anymore
  • *
* * @param emoji * The emoji reference to retrieve * * @return {@link RestAction} - Type: {@link RichCustomEmoji} */ @Nonnull @CheckReturnValue default RestAction retrieveEmoji(@Nonnull CustomEmoji emoji) { Checks.notNull(emoji, "Emoji"); if (emoji instanceof RichCustomEmoji && ((RichCustomEmoji) emoji).getGuild() != null) Checks.check(((RichCustomEmoji) emoji).getGuild().equals(this), "Emoji must be from the same Guild!"); JDA jda = getJDA(); return new DeferredRestAction<>(jda, RichCustomEmoji.class, () -> { if (emoji instanceof RichCustomEmoji) { RichCustomEmoji richEmoji = (RichCustomEmoji) emoji; if (richEmoji.getOwner() != null || !getSelfMember().hasPermission(Permission.MANAGE_GUILD_EXPRESSIONS)) return richEmoji; } return null; }, () -> retrieveEmojiById(emoji.getId())); } /** * Retrieves all the stickers from this guild. *
This also includes {@link GuildSticker#isAvailable() unavailable} stickers. * * @return {@link RestAction} - Type: List of {@link GuildSticker} */ @Nonnull @CheckReturnValue RestAction> retrieveStickers(); /** * Attempts to retrieve a {@link GuildSticker} object for this guild based on the provided snowflake reference. * *

The returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} can encounter the following Discord errors: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_STICKER UNKNOWN_STICKER} *
    Occurs when the provided id does not refer to a sticker known by Discord.
  • *
* * @param sticker * The reference of the requested {@link Sticker}. *
Can be {@link RichSticker}, {@link StickerItem}, or {@link Sticker#fromId(long)}. * * @throws IllegalArgumentException * If null is provided * * @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link GuildSticker} *
On request, gets the sticker with id matching provided id from Discord. */ @Nonnull @CheckReturnValue RestAction retrieveSticker(@Nonnull StickerSnowflake sticker); /** * Modify a sticker using {@link GuildStickerManager}. *
You can update multiple fields at once, by calling the respective setters before executing the request. * *

The returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} can encounter the following Discord errors: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_STICKER UNKNOWN_STICKER} *
    Occurs when the provided id does not refer to a sticker known by Discord.
  • *
* * @throws IllegalArgumentException * If null is provided * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException * If the currently logged in account does not have {@link Permission#MANAGE_GUILD_EXPRESSIONS MANAGE_GUILD_EXPRESSIONS} in the guild. * * @return {@link GuildStickerManager} */ @Nonnull @CheckReturnValue GuildStickerManager editSticker(@Nonnull StickerSnowflake sticker); /** * Retrieves an immutable list of the currently banned {@link net.dv8tion.jda.api.entities.User Users}. *
If you wish to ban or unban a user, use either {@link #ban(UserSnowflake, int, TimeUnit)} or * {@link #unban(UserSnowflake)}. * *

Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by * the returned {@link RestAction RestAction} include the following: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS} *
    The ban list cannot be fetched due to a permission discrepancy
  • *
* * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException * If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#BAN_MEMBERS} permission. * * @return The {@link net.dv8tion.jda.api.requests.restaction.pagination.BanPaginationAction BanPaginationAction} of the guild's bans. */ @Nonnull @CheckReturnValue BanPaginationAction retrieveBanList(); /** * Retrieves a {@link net.dv8tion.jda.api.entities.Guild.Ban Ban} of the provided {@link UserSnowflake}. *
If you wish to ban or unban a user, use either {@link #ban(UserSnowflake, int, TimeUnit)} or {@link #unban(UserSnowflake)}. * *

Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by * the returned {@link RestAction RestAction} include the following: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS} *
    The ban list cannot be fetched due to a permission discrepancy
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_BAN UNKNOWN_BAN} *
    Either the ban was removed before finishing the task or it did not exist in the first place
  • *
* * @param user * The {@link UserSnowflake} for the banned user. * This can be a user instance or {@link User#fromId(long)}. * * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException * If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#BAN_MEMBERS} permission. * * @return {@link RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.Guild.Ban Ban} *
An unmodifiable ban object for the user banned from this guild */ @Nonnull @CheckReturnValue RestAction retrieveBan(@Nonnull UserSnowflake user); /** * The method calculates the amount of Members that would be pruned if {@link #prune(int, Role...)} was executed. * Prunability is determined by a Member being offline for at least days days. * *

Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by * the returned {@link RestAction RestAction} include the following: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS} *
    The prune count cannot be fetched due to a permission discrepancy
  • *
* * @param days * Minimum number of days since a member has been offline to get affected. * * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException * If the account doesn't have {@link net.dv8tion.jda.api.Permission#KICK_MEMBERS KICK_MEMBER} Permission. * @throws IllegalArgumentException * If the provided days are less than {@code 1} or more than {@code 30} * * @return {@link RestAction RestAction} - Type: Integer *
The amount of Members that would be affected. */ @Nonnull @CheckReturnValue RestAction retrievePrunableMemberCount(int days); /** * The @everyone {@link Role Role} of this {@link net.dv8tion.jda.api.entities.Guild Guild}. *
This role is special because its {@link Role#getPosition() position} is calculated as * {@code -1}. All other role positions are 0 or greater. This implies that the public role is always below * any custom roles created in this Guild. Additionally, all members of this guild are implied to have this role so * it is not included in the list returned by {@link net.dv8tion.jda.api.entities.Member#getRoles() Member.getRoles()}. *
The ID of this Role is the Guild's ID thus it is equivalent to using {@link #getRoleById(long) getRoleById(getIdLong())}. * * @return The @everyone {@link Role Role} */ @Nonnull Role getPublicRole(); /** * The default {@link StandardGuildChannel} for a {@link net.dv8tion.jda.api.entities.Guild Guild}. *
This is the channel that the Discord client will default to opening when a Guild is opened for the first time when accepting an invite * that is not directed at a specific {@link IInviteContainer channel}. * *

Note: This channel is the first channel in the guild (ordered by position) that the {@link #getPublicRole()} * has the {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} in. * * @return The {@link StandardGuildChannel channel} representing the default channel for this guild */ @Nullable DefaultGuildChannelUnion getDefaultChannel(); /** * Returns the {@link GuildManager GuildManager} for this Guild, used to modify * all properties and settings of the Guild. *
You modify multiple fields in one request by chaining setters before calling {@link RestAction#queue() RestAction.queue()}. * * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException * If the currently logged in account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER Permission.MANAGE_SERVER} * * @return The Manager of this Guild */ @Nonnull GuildManager getManager(); /** * Returns whether this Guild has its boost progress bar shown. * * @return True, if this Guild has its boost progress bar shown */ boolean isBoostProgressBarEnabled(); /** * A {@link PaginationAction PaginationAction} implementation * that allows to {@link Iterable iterate} over all {@link net.dv8tion.jda.api.audit.AuditLogEntry AuditLogEntries} of * this Guild. *
This iterates from the most recent action to the first logged one. (Limit 90 days into history by discord api) * *

Examples
*

{@code
     * public void logBan(GuildBanEvent event) {
     *     Guild guild = event.getGuild();
     *     List modLog = guild.getTextChannelsByName("mod-log", true);
     *     guild.retrieveAuditLogs()
     *          .type(ActionType.BAN) // filter by type
     *          .limit(1)
     *          .queue(list -> {
     *             if (list.isEmpty()) return;
     *             AuditLogEntry entry = list.get(0);
     *             String message = String.format("%#s banned %#s with reason %s",
     *                                            entry.getUser(), event.getUser(), entry.getReason());
     *             modLog.forEach(channel ->
     *               channel.sendMessage(message).queue()
     *             );
     *          });
     * }
     * }
* * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException * If the currently logged in account * does not have the permission {@link net.dv8tion.jda.api.Permission#VIEW_AUDIT_LOGS VIEW_AUDIT_LOGS} * * @return {@link AuditLogPaginationAction AuditLogPaginationAction} */ @Nonnull @CheckReturnValue AuditLogPaginationAction retrieveAuditLogs(); /** * Used to leave a Guild. If the currently logged in account is the owner of this guild ({@link net.dv8tion.jda.api.entities.Guild#getOwner()}) * then ownership of the Guild needs to be transferred to a different {@link net.dv8tion.jda.api.entities.Member Member} * before leaving using {@link #transferOwnership(Member)}. * * @throws java.lang.IllegalStateException * Thrown if the currently logged in account is the Owner of this Guild. * * @return {@link RestAction RestAction} - Type: {@link java.lang.Void} */ @Nonnull @CheckReturnValue RestAction leave(); /** * Used to completely delete a Guild. This can only be done if the currently logged in account is the owner of the Guild. *
If the account has MFA enabled, use {@link #delete(String)} instead to provide the MFA code. * * @throws net.dv8tion.jda.api.exceptions.PermissionException * Thrown if the currently logged in account is not the owner of this Guild. * @throws java.lang.IllegalStateException * If the currently logged in account has MFA enabled. ({@link net.dv8tion.jda.api.entities.SelfUser#isMfaEnabled()}). * * @return {@link RestAction} - Type: {@link java.lang.Void} */ @Nonnull @CheckReturnValue RestAction delete(); /** * Used to completely delete a guild. This can only be done if the currently logged in account is the owner of the Guild. *
This method is specifically used for when MFA is enabled on the logged in account {@link SelfUser#isMfaEnabled()}. * If MFA is not enabled, use {@link #delete()}. * * @param mfaCode * The Multifactor Authentication code generated by an app like * Google Authenticator. *
This is not the MFA token given to you by Discord. The code is typically 6 characters long. * * @throws net.dv8tion.jda.api.exceptions.PermissionException * Thrown if the currently logged in account is not the owner of this Guild. * @throws java.lang.IllegalArgumentException * If the provided {@code mfaCode} is {@code null} or empty when {@link SelfUser#isMfaEnabled()} is true. * * @return {@link RestAction} - Type: {@link java.lang.Void} */ @Nonnull @CheckReturnValue RestAction delete(@Nullable String mfaCode); /** * The {@link net.dv8tion.jda.api.managers.AudioManager AudioManager} that represents the * audio connection for this Guild. *
If no AudioManager exists for this Guild, this will create a new one. *
This operation is synchronized on all audio managers for this JDA instance, * this means that calling getAudioManager() on any other guild while a thread is accessing this method may be locked. * * @throws IllegalStateException * If {@link GatewayIntent#GUILD_VOICE_STATES} is disabled * * @return The AudioManager for this Guild. * * @see net.dv8tion.jda.api.JDA#getAudioManagerCache() JDA.getAudioManagerCache() */ @Nonnull AudioManager getAudioManager(); /** * Once the currently logged in account is connected to a {@link StageChannel}, * this will trigger a {@link GuildVoiceState#getRequestToSpeakTimestamp() Request-to-Speak} (aka raise your hand). * *

This will set an internal flag to automatically request to speak once the bot joins a stage channel. *
You can use {@link #cancelRequestToSpeak()} to move back to the audience or cancel your pending request. * *

If the self member has {@link Permission#VOICE_MUTE_OTHERS} this will immediately promote them to speaker. * *

Example: *

{@code
     * stageChannel.createStageInstance("Talent Show").queue()
     * guild.requestToSpeak(); // Set request to speak flag
     * guild.getAudioManager().openAudioConnection(stageChannel); // join the channel
     * }
* * @return {@link Task} representing the request to speak. * Calling {@link Task#get()} can result in deadlocks and should be avoided at all times. * * @see #cancelRequestToSpeak() */ @Nonnull Task requestToSpeak(); /** * Cancels the {@link #requestToSpeak() Request-to-Speak}. *
This can also be used to move back to the audience if you are currently a speaker. * *

If there is no request to speak or the member is not currently connected to a {@link StageChannel}, this does nothing. * * @return {@link Task} representing the request to speak cancellation. * Calling {@link Task#get()} can result in deadlocks and should be avoided at all times. * * @see #requestToSpeak() */ @Nonnull Task cancelRequestToSpeak(); /** * Returns the {@link net.dv8tion.jda.api.JDA JDA} instance of this Guild * * @return the corresponding JDA instance */ @Nonnull JDA getJDA(); /** * Retrieves all {@link net.dv8tion.jda.api.entities.Invite Invites} for this guild. *
Requires {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} in this guild. * Will throw an {@link net.dv8tion.jda.api.exceptions.InsufficientPermissionException InsufficientPermissionException} otherwise. * *

To get all invites for a {@link GuildChannel GuildChannel} * use {@link IInviteContainer#retrieveInvites() GuildChannel.retrieveInvites()} * * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException * if the account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} in this Guild. * * @return {@link RestAction RestAction} - Type: List{@literal <}{@link net.dv8tion.jda.api.entities.Invite Invite}{@literal >} *
The list of expanded Invite objects * * @see IInviteContainer#retrieveInvites() */ @Nonnull @CheckReturnValue RestAction> retrieveInvites(); /** * Retrieves all {@link net.dv8tion.jda.api.entities.templates.Template Templates} for this guild. *
Requires {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} in this guild. * Will throw an {@link net.dv8tion.jda.api.exceptions.InsufficientPermissionException InsufficientPermissionException} otherwise. * * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException * if the account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} in this Guild. * * @return {@link RestAction RestAction} - Type: List{@literal <}{@link net.dv8tion.jda.api.entities.templates.Template Template}{@literal >} *
The list of Template objects */ @Nonnull @CheckReturnValue RestAction> retrieveTemplates(); /** * Used to create a new {@link net.dv8tion.jda.api.entities.templates.Template Template} for this Guild. *
Requires {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} in this Guild. * Will throw an {@link net.dv8tion.jda.api.exceptions.InsufficientPermissionException InsufficientPermissionException} otherwise. * *

Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} include: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#ALREADY_HAS_TEMPLATE Guild already has a template} *
    The guild already has a template.
  • *
* * @param name * The name of the template * @param description * The description of the template * * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException * if the account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} in this Guild * @throws IllegalArgumentException * If the provided name is {@code null} or not between 1-100 characters long, or * if the provided description is not between 0-120 characters long * * @return {@link RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.templates.Template Template} *
The created Template object */ @Nonnull @CheckReturnValue RestAction