Interface JDA


  • public interface JDA
    The core of JDA. Acts as a registry system of JDA. All parts of the the API can be accessed starting from this class.
    • Method Detail

      • getStatus

        JDA.Status getStatus()
        Gets the current Status of the JDA instance.
        Returns:
        Current JDA status.
      • getPing

        long getPing()
        The time in milliseconds that discord took to respond to our last heartbeat
        This roughly represents the WebSocket ping of this session

        RestAction request times do not correlate to this value!

        Returns:
        time in milliseconds between heartbeat and the heartbeat ack response
      • awaitReady

        default JDA awaitReady()
                        throws java.lang.InterruptedException
        This method will block until JDA has reached the status JDA.Status.CONNECTED.
        This status means that JDA finished setting up its internal cache and is ready to be used.
        Returns:
        The current JDA instance, for chaining convenience
        Throws:
        java.lang.InterruptedException - If this thread is interrupted while waiting
        java.lang.IllegalStateException - If JDA is shutdown during this wait period
      • getCloudflareRays

        java.util.List<java.lang.String> getCloudflareRays()
        Contains all cf-ray headers that JDA received in this session.
        These receive a new value whenever the WebSockedClient reconnects to the gateway.

        This is useful to monitor cloudflare activity from the Discord Developer perspective.
        Use this list to report connection issues.

        Returns:
        Immutable list of all cf-ray values for this session
      • getWebSocketTrace

        java.util.List<java.lang.String> getWebSocketTrace()
        Receives all valid _trace lines that have been sent to us in this session.
        These values reset on every reconnect! (not resume)
        Returns:
        List of all websocket traces
      • addEventListener

        void addEventListener​(java.lang.Object... listeners)
        Adds all provided listeners to the event-listeners that will be used to handle events. This uses the InterfacedEventListener by default. To switch to the AnnotatedEventManager, use setEventManager(IEventManager). Note: when using the InterfacedEventListener (default), given listener must be instance of EventListener!
        Parameters:
        listeners - The listener(s) which will react to events.
        Throws:
        java.lang.IllegalArgumentException - If either listeners or one of it's objects is null.
      • removeEventListener

        void removeEventListener​(java.lang.Object... listeners)
        Removes all provided listeners from the event-listeners and no longer uses them to handle events.
        Parameters:
        listeners - The listener(s) to be removed.
        Throws:
        java.lang.IllegalArgumentException - If either listeners or one of it's objects is null.
      • getRegisteredListeners

        java.util.List<java.lang.Object> getRegisteredListeners()
        Returns an unmodifiable List of Objects that have been registered as EventListeners.
        Returns:
        List of currently registered Objects acting as EventListeners.
      • createGuild

        GuildAction createGuild​(java.lang.String name)
        Constructs a new Guild with the specified name
        Use the returned GuildAction to provide further details and settings for the resulting Guild!

        This RestAction does not provide the resulting Guild! It will be in a following GuildJoinEvent.

        Parameters:
        name - The name of the resulting guild
        Returns:
        GuildAction
        Allows for setting various details for the resulting Guild
        Throws:
        java.lang.IllegalStateException - If the currently logged in account is from
        java.lang.IllegalArgumentException - If the provided name is empty, null or not between 2-100 characters
      • getAudioManagerCache

        CacheView<AudioManager> getAudioManagerCache()
        CacheView of all cached AudioManagers created for this JDA instance.
        AudioManagers are created when first retrieved via Guild.getAudioManager(). Using this will perform better than calling Guild.getAudioManager() iteratively as that would cause many useless audio managers to be created!

        AudioManagers are cross-session persistent!

        Returns:
        CacheView
      • getAudioManagers

        default java.util.List<AudioManager> getAudioManagers()
        Immutable list of all created AudioManagers for this JDA instance!
        Returns:
        Immutable list of all created AudioManager instances
      • getUsers

        default java.util.List<User> getUsers()
        An unmodifiable list of all Users that share a Guild with the currently logged in account.
        This list will never contain duplicates and represents all Users that JDA can currently see.

        If the developer is sharding, then only users from guilds connected to the specifically logged in shard will be returned in the List.

        Returns:
        List of all Users that are visible to JDA.
      • getUserById

        default User getUserById​(java.lang.String id)
        This returns the User which has the same id as the one provided.
        If there is no visible user with an id that matches the provided one, this returns null.
        Parameters:
        id - The id of the requested User.
        Returns:
        Possibly-null User with matching id.
        Throws:
        java.lang.NumberFormatException - If the provided id cannot be parsed by Long.parseLong(String)
      • getUserById

        default User getUserById​(long id)
        This returns the User which has the same id as the one provided.
        If there is no visible user with an id that matches the provided one, this returns null.
        Parameters:
        id - The id of the requested User.
        Returns:
        Possibly-null User with matching id.
      • getUsersByName

        default java.util.List<User> getUsersByName​(java.lang.String name,
                                                    boolean ignoreCase)
        This unmodifiable returns all Users that have the same username as the one provided.
        If there are no Users with the provided name, then this returns an empty list.

        Note: This does **not** consider nicknames, it only considers User.getName()

        Parameters:
        name - The name of the requested Users.
        ignoreCase - Whether to ignore case or not when comparing the provided name to each User.getName().
        Returns:
        Possibly-empty list of Users that all have the same name as the provided name.
      • getMutualGuilds

        java.util.List<Guild> getMutualGuilds​(User... users)
        Gets all Guilds that contain all given users as their members.
        Parameters:
        users - The users which all the returned Guilds must contain.
        Returns:
        Unmodifiable list of all Guild instances which have all Users in them.
      • getMutualGuilds

        java.util.List<Guild> getMutualGuilds​(java.util.Collection<User> users)
        Gets all Guilds that contain all given users as their members.
        Parameters:
        users - The users which all the returned Guilds must contain.
        Returns:
        Unmodifiable list of all Guild instances which have all Users in them.
      • retrieveUserById

        @CheckReturnValue
        RestAction<User> retrieveUserById​(java.lang.String id)
        Attempts to retrieve a User object based on the provided id.
        This first calls getUserById(long), and if the return is null then a request is made to the Discord servers.

        The returned RestAction can encounter the following Discord errors:

        • ErrorResponse.UNKNOWN_USER
          Occurs when the provided id does not refer to a User known by Discord. Typically occurs when developers provide an incomplete id (cut short).
        Parameters:
        id - The id of the requested User.
        Returns:
        RestAction - Type: User
        On request, gets the User with id matching provided id from Discord.
        Throws:
        AccountTypeException - This endpoint is AccountType.BOT only.
        java.lang.NumberFormatException - If the provided id cannot be parsed by Long.parseLong(String)
        java.lang.IllegalArgumentException -
        • If the provided id String is null.
        • If the provided id String is empty.
      • retrieveUserById

        @CheckReturnValue
        RestAction<User> retrieveUserById​(long id)
        Attempts to retrieve a User object based on the provided id.
        This first calls getUserById(long), and if the return is null then a request is made to the Discord servers.

        The returned RestAction can encounter the following Discord errors:

        • ErrorResponse.UNKNOWN_USER
          Occurs when the provided id does not refer to a User known by Discord. Typically occurs when developers provide an incomplete id (cut short).
        Parameters:
        id - The id of the requested User.
        Returns:
        RestAction - Type: User
        On request, gets the User with id matching provided id from Discord.
        Throws:
        AccountTypeException - This endpoint is AccountType.BOT only.
      • getGuilds

        default java.util.List<Guild> getGuilds()
        An unmodifiable List of all Guilds that the logged account is connected to.
        If this account is not connected to any Guilds, this will return an empty list.

        If the developer is sharding (JDABuilder.useSharding(int, int), then this list will only contain the Guilds that the shard is actually connected to. Discord determines which guilds a shard is connect to using the following format:
        Guild connected if shardId == (guildId >> 22) % totalShards;
        Source for formula: Discord Documentation

        Returns:
        Possibly-empty list of all the Guilds that this account is connected to.
      • getGuildById

        default Guild getGuildById​(java.lang.String id)
        This returns the Guild which has the same id as the one provided.
        If there is no connected guild with an id that matches the provided one, then this returns null.
        Parameters:
        id - The id of the Guild.
        Returns:
        Possibly-null Guild with matching id.
        Throws:
        java.lang.NumberFormatException - If the provided id cannot be parsed by Long.parseLong(String)
      • getGuildById

        default Guild getGuildById​(long id)
        This returns the Guild which has the same id as the one provided.
        If there is no connected guild with an id that matches the provided one, then this returns null.
        Parameters:
        id - The id of the Guild.
        Returns:
        Possibly-null Guild with matching id.
      • getGuildsByName

        default java.util.List<Guild> getGuildsByName​(java.lang.String name,
                                                      boolean ignoreCase)
        An unmodifiable list of all Guilds that have the same name as the one provided.
        If there are no Guilds with the provided name, then this returns an empty list.
        Parameters:
        name - The name of the requested Guilds.
        ignoreCase - Whether to ignore case or not when comparing the provided name to each Guild.getName().
        Returns:
        Possibly-empty list of all the Guilds that all have the same name as the provided name.
      • getRoles

        default java.util.List<Role> getRoles()
        All Roles this JDA instance can see.
        This will iterate over each Guild retrieved from getGuilds() and collect its Guild.getRoles().
        Returns:
        Immutable List of all visible Roles
      • getRoleById

        default Role getRoleById​(java.lang.String id)
        Retrieves the Role associated to the provided id.
        This iterates over all Guilds and check whether a Role from that Guild is assigned to the specified ID and will return the first that can be found.
        Parameters:
        id - The id of the searched Role
        Returns:
        Possibly-null Role for the specified ID
        Throws:
        java.lang.NumberFormatException - If the provided id cannot be parsed by Long.parseLong(String)
      • getRoleById

        default Role getRoleById​(long id)
        Retrieves the Role associated to the provided id.
        This iterates over all Guilds and check whether a Role from that Guild is assigned to the specified ID and will return the first that can be found.
        Parameters:
        id - The id of the searched Role
        Returns:
        Possibly-null Role for the specified ID
      • getRolesByName

        default java.util.List<Role> getRolesByName​(java.lang.String name,
                                                    boolean ignoreCase)
        Retrieves all Roles visible to this JDA instance.
        This simply filters the Roles returned by getRoles() with the provided name, either using String.equals(Object) or String.equalsIgnoreCase(String) on Role.getName().
        Parameters:
        name - The name for the Roles
        ignoreCase - Whether to use String.equalsIgnoreCase(String)
        Returns:
        Immutable List of all Roles matching the parameters provided.
      • getCategoryById

        default Category getCategoryById​(java.lang.String id)
        Gets the Category that matches the provided id.
        If there is no matching Category this returns null.
        Parameters:
        id - The snowflake ID of the wanted Category
        Returns:
        Possibly-null Category for the provided ID.
        Throws:
        java.lang.IllegalArgumentException - If the provided ID is not a valid long
      • getCategoryById

        default Category getCategoryById​(long id)
        Gets the Category that matches the provided id.
        If there is no matching Category this returns null.
        Parameters:
        id - The snowflake ID of the wanted Category
        Returns:
        Possibly-null Category for the provided ID.
      • getCategories

        default java.util.List<Category> getCategories()
        Gets all Categories visible to the currently logged in account.
        Returns:
        An immutable list of all visible Categories.
      • getCategoriesByName

        default java.util.List<Category> getCategoriesByName​(java.lang.String name,
                                                             boolean ignoreCase)
        Gets a list of all Categories that have the same name as the one provided.
        If there are no matching categories this will return an empty list.
        Parameters:
        name - The name to check
        ignoreCase - Whether to ignore case on name checking
        Returns:
        Immutable list of all categories matching the provided name
        Throws:
        java.lang.IllegalArgumentException - If the provided name is null
      • getTextChannels

        default java.util.List<TextChannel> getTextChannels()
        An unmodifiable List of all TextChannels of all connected Guilds.

        Note: just because a TextChannel is present in this list does not mean that you will be able to send messages to it. Furthermore, if you log into this account on the discord client, it is possible that you will see fewer channels than this returns. This is because the discord client hides any TextChannel that you don't have the Permission.MESSAGE_READ permission in.

        Returns:
        Possibly-empty list of all known TextChannels.
      • getTextChannelById

        default TextChannel getTextChannelById​(java.lang.String id)
        This returns the TextChannel which has the same id as the one provided.
        If there is no known TextChannel with an id that matches the provided one, then this returns null.

        Note: just because a TextChannel is present does not mean that you will be able to send messages to it. Furthermore, if you log into this account on the discord client, it is you will not see the channel that this returns. This is because the discord client hides any TextChannel that you don't have the Permission.MESSAGE_READ permission in.

        Parameters:
        id - The id of the TextChannel.
        Returns:
        Possibly-null TextChannel with matching id.
        Throws:
        java.lang.NumberFormatException - If the provided id cannot be parsed by Long.parseLong(String)
      • getTextChannelById

        default TextChannel getTextChannelById​(long id)
        This returns the TextChannel which has the same id as the one provided.
        If there is no known TextChannel with an id that matches the provided one, then this returns null.

        Note: just because a TextChannel is present does not mean that you will be able to send messages to it. Furthermore, if you log into this account on the discord client, it is you will not see the channel that this returns. This is because the discord client hides any TextChannel that you don't have the Permission.MESSAGE_READ permission in.

        Parameters:
        id - The id of the TextChannel.
        Returns:
        Possibly-null TextChannel with matching id.
      • getTextChannelsByName

        default java.util.List<TextChannel> getTextChannelsByName​(java.lang.String name,
                                                                  boolean ignoreCase)
        An unmodifiable list of all TextChannels that have the same name as the one provided.
        If there are no TextChannels with the provided name, then this returns an empty list.

        Note: just because a TextChannel is present in this list does not mean that you will be able to send messages to it. Furthermore, if you log into this account on the discord client, it is possible that you will see fewer channels than this returns. This is because the discord client hides any TextChannel that you don't have the Permission.MESSAGE_READ permission in.

        Parameters:
        name - The name of the requested TextChannels.
        ignoreCase - Whether to ignore case or not when comparing the provided name to each Channel.getName().
        Returns:
        Possibly-empty list of all the TextChannels that all have the same name as the provided name.
      • getVoiceChannelById

        default VoiceChannel getVoiceChannelById​(java.lang.String id)
        This returns the VoiceChannel which has the same id as the one provided.
        If there is no known VoiceChannel with an id that matches the provided one, then this returns null.
        Parameters:
        id - The id of the VoiceChannel.
        Returns:
        Possibly-null VoiceChannel with matching id.
        Throws:
        java.lang.NumberFormatException - If the provided id cannot be parsed by Long.parseLong(String)
      • getVoiceChannelById

        default VoiceChannel getVoiceChannelById​(long id)
        This returns the VoiceChannel which has the same id as the one provided.
        If there is no known VoiceChannel with an id that matches the provided one, then this returns null.
        Parameters:
        id - The id of the VoiceChannel.
        Returns:
        Possibly-null VoiceChannel with matching id.
      • getVoiceChannelByName

        default java.util.List<VoiceChannel> getVoiceChannelByName​(java.lang.String name,
                                                                   boolean ignoreCase)
        An unmodifiable list of all VoiceChannels that have the same name as the one provided.
        If there are no VoiceChannels with the provided name, then this returns an empty list.
        Parameters:
        name - The name of the requested VoiceChannels.
        ignoreCase - Whether to ignore case or not when comparing the provided name to each Channel.getName().
        Returns:
        Possibly-empty list of all the VoiceChannels that all have the same name as the provided name.
      • getPrivateChannelById

        default PrivateChannel getPrivateChannelById​(java.lang.String id)
        This returns the PrivateChannel which has the same id as the one provided.
        If there is no known PrivateChannel with an id that matches the provided one, then this returns null.
        Parameters:
        id - The id of the PrivateChannel.
        Returns:
        Possibly-null PrivateChannel with matching id.
        Throws:
        java.lang.NumberFormatException - If the provided id cannot be parsed by Long.parseLong(String)
      • getPrivateChannelById

        default PrivateChannel getPrivateChannelById​(long id)
        This returns the PrivateChannel which has the same id as the one provided.
        If there is no known PrivateChannel with an id that matches the provided one, then this returns null.
        Parameters:
        id - The id of the PrivateChannel.
        Returns:
        Possibly-null PrivateChannel with matching id.
      • getEmoteById

        default Emote getEmoteById​(java.lang.String id)
        Retrieves an emote matching the specified id if one is available in our cache.
        This will be null if CacheFlag.EMOTE is disabled.

        Unicode emojis are not included as Emote!

        Parameters:
        id - The id of the requested Emote.
        Returns:
        An Emote represented by this id or null if none is found in our cache.
        Throws:
        java.lang.NumberFormatException - If the provided id cannot be parsed by Long.parseLong(String)
      • getEmoteById

        default Emote getEmoteById​(long id)
        Retrieves an emote matching the specified id if one is available in our cache.
        This will be null if CacheFlag.EMOTE is disabled.

        Unicode emojis are not included as Emote!

        Parameters:
        id - The id of the requested Emote.
        Returns:
        An Emote represented by this id or null if none is found in our cache.
      • getEmotesByName

        default java.util.List<Emote> getEmotesByName​(java.lang.String name,
                                                      boolean ignoreCase)
        An unmodifiable list of all Emotes that have the same name as the one provided.
        If there are no Emotes with the provided name, then this returns an empty list.
        This will be empty if CacheFlag.EMOTE is disabled.

        Unicode emojis are not included as Emote!

        Parameters:
        name - The name of the requested Emotes.
        ignoreCase - Whether to ignore case or not when comparing the provided name to each Emote.getName().
        Returns:
        Possibly-empty list of all the Emotes that all have the same name as the provided name.
      • getSelfUser

        SelfUser getSelfUser()
        Returns the currently logged in account represented by SelfUser.
        Account settings cannot be modified using this object. If you wish to modify account settings please use the AccountManager which is accessible by SelfUser.getManager().
        Returns:
        The currently logged in account.
      • getShardInfo

        JDA.ShardInfo getShardInfo()
        The shard information used when creating this instance of JDA.
        Represents the information provided to JDABuilder.useSharding(int, int).
        Returns:
        The shard information for this shard or null if this JDA instance isn't sharding.
      • getToken

        java.lang.String getToken()
        The login token that is currently being used for Discord authentication.
        Returns:
        Never-null, 18 character length string containing the auth token.
      • getResponseTotal

        long getResponseTotal()
        This value is the total amount of JSON responses that discord has sent.
        This value resets every time the websocket has to perform a full reconnect (not resume).
        Returns:
        Never-negative long containing total response amount.
      • getMaxReconnectDelay

        int getMaxReconnectDelay()
        This value is the maximum amount of time, in seconds, that JDA will wait between reconnect attempts.
        Can be set using JDABuilder.setMaxReconnectDelay(int).
        Returns:
        The maximum amount of time JDA will wait between reconnect attempts in seconds.
      • setAutoReconnect

        void setAutoReconnect​(boolean reconnect)
        Sets whether or not JDA should try to automatically reconnect if a connection-error is encountered.
        This will use an incremental reconnect (timeouts are increased each time an attempt fails).

        Default is true.

        Parameters:
        reconnect - If true - enables autoReconnect
      • setRequestTimeoutRetry

        void setRequestTimeoutRetry​(boolean retryOnTimeout)
        Whether the Requester should retry when a SocketTimeoutException occurs.
        Parameters:
        retryOnTimeout - True, if the Request should retry once on a socket timeout
      • isAutoReconnect

        boolean isAutoReconnect()
        USed to determine whether or not autoReconnect is enabled for JDA.
        Returns:
        True if JDA will attempt to automatically reconnect when a connection-error is encountered.
      • isAudioEnabled

        boolean isAudioEnabled()
        Used to determine whether the instance of JDA supports audio and has it enabled.
        Returns:
        True if JDA can currently utilize the audio system.
      • isBulkDeleteSplittingEnabled

        boolean isBulkDeleteSplittingEnabled()
        Used to determine if JDA will process MESSAGE_DELETE_BULK messages received from Discord as a single MessageBulkDeleteEvent or split the deleted messages up and fire multiple MessageDeleteEvents, one for each deleted message.

        By default, JDA will separate the bulk delete event into individual delete events, but this isn't as efficient as handling a single event would be. It is recommended that BulkDelete Splitting be disabled and that the developer should instead handle the MessageBulkDeleteEvent

        Returns:
        Whether or not JDA currently handles the BULK_MESSAGE_DELETE event by splitting it into individual MessageDeleteEvents or not.
      • shutdown

        void shutdown()
        Shuts down this JDA instance, closing all its connections. After this command is issued the JDA Instance can not be used anymore. Already enqueued RestActions are still going to be executed.

        If you want this instance to shutdown without executing, use shutdownNow()

        See Also:
        shutdownNow()
      • shutdownNow

        void shutdownNow()
        Shuts down this JDA instance instantly, closing all its connections. After this command is issued the JDA Instance can not be used anymore. This will also cancel all queued RestActions.

        If you want this instance to shutdown without cancelling enqueued RestActions use shutdown()

        See Also:
        shutdown()
      • getAccountType

        AccountType getAccountType()
        The AccountType of the currently logged in account.
        Used when determining functions that are restricted based on the type of account.
        Returns:
        The current AccountType.