Interface ShardManager
- All Known Implementing Classes:
DefaultShardManager
Custom implementations may not support all methods and throw
UnsupportedOperationExceptions
instead.- Since:
- 3.4
- Author:
- Aljoscha Grebe
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
addEventListener
(Object... listeners) Adds all provided listeners to the event-listeners that will be used to handle events.default void
addEventListeners
(IntFunction<Object> eventListenerProvider) Adds listeners provided by the listener provider to each shard to the event-listeners that will be used to handle events.default double
The average time in milliseconds between all shards that discord took to respond to our last heartbeat.Gets allCategories
visible to the currently logged in account.getCategoriesByName
(String name, boolean ignoreCase) Gets a list of allCategories
that have the same name as the one provided.default Category
getCategoryById
(long id) Gets theCategory
that matches the provided id.default Category
Gets theCategory
that matches the provided id.default SnowflakeCacheView<Category>
SnowflakeCacheView
of all cachedCategories
visible to this ShardManager instance.default Emote
getEmoteById
(long id) Retrieves an emote matching the specifiedid
if one is available in our cache.default Emote
getEmoteById
(String id) Retrieves an emote matching the specifiedid
if one is available in our cache.default SnowflakeCacheView<Emote>
UnifiedSnowflakeCacheView
of all cachedEmotes
visible to this ShardManager instance.A collection of all known emotes (managed/restricted included).getEmotesByName
(String name, boolean ignoreCase) An unmodifiable list of allEmotes
that have the same name as the one provided.default EnumSet<GatewayIntent>
TheGatewayIntents
for the JDA sessions of this shard manager.default Guild
getGuildById
(long id) This returns theGuild
which has the same id as the one provided.default Guild
getGuildById
(String id) This returns theGuild
which has the same id as the one provided.default SnowflakeCacheView<Guild>
SnowflakeCacheView
of all cachedGuilds
visible to this ShardManager instance.default GuildChannel
getGuildChannelById
(long id) GetGuildChannel
for the provided ID.default GuildChannel
GetGuildChannel
for the provided ID.default GuildChannel
getGuildChannelById
(ChannelType type, long id) GetGuildChannel
for the provided ID.default GuildChannel
getGuildChannelById
(ChannelType type, String id) GetGuildChannel
for the provided ID.An unmodifiable List of allGuilds
that the logged account is connected to.getGuildsByName
(String name, boolean ignoreCase) An unmodifiable list of allGuilds
that have the same name as the one provided.getMutualGuilds
(Collection<User> users) Gets allGuilds
that contain all given users as their members.getMutualGuilds
(User... users) Gets allGuilds
that contain all given users as their members.default PrivateChannel
getPrivateChannelById
(long id) This returns thePrivateChannel
which has the same id as the one provided.default PrivateChannel
This returns thePrivateChannel
which has the same id as the one provided.default SnowflakeCacheView<PrivateChannel>
SnowflakeCacheView
of all cachedPrivateChannels
visible to this ShardManager instance.default List<PrivateChannel>
An unmodifiable list of all knownPrivateChannels
.default Role
getRoleById
(long id) Retrieves theRole
associated to the provided id.default Role
getRoleById
(String id) Retrieves theRole
associated to the provided id.default SnowflakeCacheView<Role>
UnifiedSnowflakeCacheView
of all cachedRoles
visible to this ShardManager instance.getRoles()
AllRoles
this ShardManager instance can see.getRolesByName
(String name, boolean ignoreCase) Retrieves allRoles
visible to this ShardManager instance.default JDA
getShardById
(int id) This returns theJDA
instance which has the same id as the one provided.default JDA
getShardById
(String id) This returns theJDA
instance which has the same id as the one provided.UnifiedShardCacheView
of all cachedJDA
bound to this ShardManager instance.Gets allJDA
instances bound to this ShardManager.int
Returns the amount of shards queued for (re)connecting.default int
Returns the amount of running shards.default int
Returns the amount of shards managed by thisShardManager
.default JDA.Status
getStatus
(int shardId) This returns theJDA.Status
of the shard which has the same id as the one provided.default Map<JDA,
JDA.Status> Gets the currentStatus
of all shards.default StoreChannel
getStoreChannelById
(long id) This returns theStoreChannel
which has the same id as the one provided.default StoreChannel
This returns theStoreChannel
which has the same id as the one provided.default SnowflakeCacheView<StoreChannel>
SnowflakeCacheView
of all cachedStoreChannels
visible to this ShardManager instance.default List<StoreChannel>
An unmodifiable List of allStoreChannels
of all connectedGuilds
.default TextChannel
getTextChannelById
(long id) This returns theTextChannel
which has the same id as the one provided.default TextChannel
This returns theTextChannel
which has the same id as the one provided.default SnowflakeCacheView<TextChannel>
SnowflakeCacheView
of all cachedTextChannels
visible to this ShardManager instance.default List<TextChannel>
An unmodifiable List of allTextChannels
of all connectedGuilds
.default User
getUserById
(long id) This returns theUser
which has the same id as the one provided.default User
getUserById
(String id) This returns theUser
which has the same id as the one provided.default User
getUserByTag
(String tag) Searches for the first user that has the matching Discord Tag.default User
getUserByTag
(String username, String discriminator) Searches for the first user that has the matching Discord Tag.default SnowflakeCacheView<User>
SnowflakeCacheView
of all cachedUsers
visible to this ShardManager instance.getUsers()
default VoiceChannel
getVoiceChannelById
(long id) This returns theVoiceChannel
which has the same id as the one provided.default VoiceChannel
This returns theVoiceChannel
which has the same id as the one provided.default SnowflakeCacheView<VoiceChannel>
SnowflakeCacheView
of all cachedVoiceChannels
visible to this ShardManager instance.default List<VoiceChannel>
An unmodifiable list of allVoiceChannels
of all connectedGuilds
.void
login()
Initializes and starts all shards.default void
removeEventListener
(Object... listeners) Removes all provided listeners from the event-listeners and no longer uses them to handle events.default void
removeEventListenerProvider
(IntFunction<Object> eventListenerProvider) Remove a listener provider.default void
removeEventListeners
(IntFunction<Collection<Object>> eventListenerProvider) Remove listeners from shards by their id.void
restart()
Restarts all shards, shutting old ones down first.void
restart
(int id) Restarts the shards with the given id only.default RestAction<ApplicationInfo>
Used to access application details of this bot.default RestAction<User>
retrieveUserById
(long id) Attempts to retrieve aUser
object based on the provided id.default RestAction<User>
Attempts to retrieve aUser
object based on the provided id.default void
setActivity
(Activity activity) Sets theActivity
for all shards.default void
setActivityProvider
(IntFunction<? extends Activity> activityProvider) Sets provider that provider theActivity
for all shards.default void
setIdle
(boolean idle) Sets whether all instances should be marked as afk or notdefault void
setIdleProvider
(IntFunction<Boolean> idleProvider) Sets the provider that decides for all shards whether they should be marked as afk or not.default void
setPresence
(OnlineStatus status, Activity activity) Sets theOnlineStatus
andActivity
for all shards.default void
setPresenceProvider
(IntFunction<OnlineStatus> statusProvider, IntFunction<? extends Activity> activityProvider) Sets the provider that provides theOnlineStatus
andActivity
for all shards.default void
setStatus
(OnlineStatus status) Sets theOnlineStatus
for all shards.default void
setStatusProvider
(IntFunction<OnlineStatus> statusProvider) Sets the provider that provides theOnlineStatus
for all shards.void
shutdown()
Shuts down all JDA shards, closing all their connections.void
shutdown
(int shardId) Shuts down the shard with the given id only.void
start
(int shardId) Adds a new shard with the given id to this ShardManager and starts it.
-
Method Details
-
addEventListener
Adds all provided listeners to the event-listeners that will be used to handle events.Note: when using the
InterfacedEventListener
(default), the given listener must be an instance ofEventListener
!- Parameters:
listeners
- The listener(s) which will react to events.- Throws:
IllegalArgumentException
- If either listeners or one of it's objects isnull
.
-
removeEventListener
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:
IllegalArgumentException
- If either listeners or one of it's objects isnull
.
-
addEventListeners
Adds listeners provided by the listener provider to each shard to the event-listeners that will be used to handle events. The listener provider gets a shard id applied and is expected to return a listener.Note: when using the
InterfacedEventListener
(default), the given listener must be an instance ofEventListener
!- Parameters:
eventListenerProvider
- The provider of listener(s) which will react to events.- Throws:
IllegalArgumentException
- If the provided listener provider or any of the listeners or provides arenull
.
-
removeEventListeners
Remove listeners from shards by their id. The provider takes shard ids, and returns a collection of listeners that shall be removed from the respective shards.- Parameters:
eventListenerProvider
- Gets shard ids applied and is expected to return a collection of listeners that shall be removed from the respective shards- Throws:
IllegalArgumentException
- If the provided event listeners provider isnull
.
-
removeEventListenerProvider
Remove a listener provider. This will stop further created / restarted shards from getting a listener added by that provider. Default is a no-op for backwards compatibility, see implementations likeDefaultShardManager.removeEventListenerProvider(IntFunction)
for actual code- Parameters:
eventListenerProvider
- The provider of listeners that shall be removed.- Throws:
IllegalArgumentException
- If the provided listener provider isnull
.
-
getShardsQueued
int getShardsQueued()Returns the amount of shards queued for (re)connecting.- Returns:
- The amount of shards queued for (re)connecting.
-
getShardsRunning
default int getShardsRunning()Returns the amount of running shards.- Returns:
- The amount of running shards.
-
getShardsTotal
default int getShardsTotal()Returns the amount of shards managed by thisShardManager
. This includes shards currently queued for a restart.- Returns:
- The managed amount of shards.
-
getGatewayIntents
TheGatewayIntents
for the JDA sessions of this shard manager.- Returns:
EnumSet
of active gateway intents
-
retrieveApplicationInfo
Used to access application details of this bot.
Since this is the same for every shard it picksJDA.retrieveApplicationInfo()
from any shard.- Returns:
- The Application registry for this bot.
- Throws:
IllegalStateException
- If there is no running shard
-
getAverageGatewayPing
default double getAverageGatewayPing()The average time in milliseconds between all shards that discord took to respond to our last heartbeat. This roughly represents the WebSocket ping of this session. If there are no shards running, this will return-1
.RestAction
request times do not correlate to this value!- Returns:
- The average time in milliseconds between heartbeat and the heartbeat ack response
-
getCategories
Gets allCategories
visible to the currently logged in account.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
getCategoryCache()
and use its more efficient versions of handling these values.- Returns:
- An immutable list of all visible
Categories
.
-
getCategoriesByName
Gets a list of allCategories
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 checkignoreCase
- Whether to ignore case on name checking- Returns:
- Immutable list of all categories matching the provided name
- Throws:
IllegalArgumentException
- If the provided name isnull
-
getCategoryById
Gets theCategory
that matches the provided id.
If there is no matchingCategory
, this will returnnull
.- Parameters:
id
- The snowflake ID of the wanted Category- Returns:
- Possibly-null
Category
for the provided ID.
-
getCategoryById
Gets theCategory
that matches the provided id.
If there is no matchingCategory
, this will returnnull
.- Parameters:
id
- The snowflake ID of the wanted Category- Returns:
- Possibly-null
Category
for the provided ID. - Throws:
IllegalArgumentException
- If the provided ID is not a validlong
-
getCategoryCache
SnowflakeCacheView
of all cachedCategories
visible to this ShardManager instance.- Returns:
SnowflakeCacheView
-
getEmoteById
Retrieves an emote matching the specifiedid
if one is available in our cache.Unicode emojis are not included as
Emote
! -
getEmoteById
Retrieves an emote matching the specifiedid
if one is available in our cache.Unicode emojis are not included as
Emote
!- Parameters:
id
- The id of the requestedEmote
.- Returns:
- An
Emote
represented by this id or null if none is found in our cache. - Throws:
NumberFormatException
- If the providedid
cannot be parsed byLong.parseLong(String)
-
getEmoteCache
UnifiedSnowflakeCacheView
of all cachedEmotes
visible to this ShardManager instance.- Returns:
- Unified
SnowflakeCacheView
-
getEmotes
A collection of all known emotes (managed/restricted included).Hint: To check whether you can use an
Emote
in a specific context you can useEmote.canInteract(net.dv8tion.jda.api.entities.Member)
orEmote.canInteract(net.dv8tion.jda.api.entities.User, net.dv8tion.jda.api.entities.MessageChannel)
Unicode emojis are not included as
Emote
!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
getEmoteCache()
and use its more efficient versions of handling these values.- Returns:
- An immutable list of Emotes (which may or may not be available to usage).
-
getEmotesByName
An unmodifiable list of allEmotes
that have the same name as the one provided.
If there are noEmotes
with the provided name, this will return an empty list.Unicode emojis are not included as
Emote
!- Parameters:
name
- The name of the requestedEmotes
. Without colons.ignoreCase
- Whether to ignore case or not when comparing the provided name to eachEmote.getName()
.- Returns:
- Possibly-empty list of all the
Emotes
that all have the same name as the provided name.
-
getGuildById
This returns theGuild
which has the same id as the one provided.
If there is no connected guild with an id that matches the provided one, this will returnnull
. -
getGuildById
This returns theGuild
which has the same id as the one provided.
If there is no connected guild with an id that matches the provided one, this will returnnull
. -
getGuildsByName
An unmodifiable list of allGuilds
that have the same name as the one provided.
If there are noGuilds
with the provided name, this will return an empty list.- Parameters:
name
- The name of the requestedGuilds
.ignoreCase
- Whether to ignore case or not when comparing the provided name to eachGuild.getName()
.- Returns:
- Possibly-empty list of all the
Guilds
that all have the same name as the provided name.
-
getGuildCache
SnowflakeCacheView
of all cachedGuilds
visible to this ShardManager instance.- Returns:
SnowflakeCacheView
-
getGuilds
An unmodifiable List of allGuilds
that the logged account is connected to.
If this account is not connected to anyGuilds
, this will return an empty 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
getGuildCache()
and use its more efficient versions of handling these values.- Returns:
- Possibly-empty list of all the
Guilds
that this account is connected to.
-
getMutualGuilds
Gets allGuilds
that contain all given users as their members. -
getMutualGuilds
Gets allGuilds
that contain all given users as their members. -
retrieveUserById
Attempts to retrieve aUser
object based on the provided id.
This first callsgetUserById(long)
, and if the return isnull
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 aUser
known by Discord. Typically occurs when developers provide an incomplete id (cut short).
- Parameters:
id
- The id of the requestedUser
.- Returns:
RestAction
- Type:User
On request, gets the User with id matching provided id from Discord.- Throws:
IllegalArgumentException
- If the provided id String is not a valid snowflake.IllegalStateException
- If there isn't any active shards.
-
retrieveUserById
Attempts to retrieve aUser
object based on the provided id.
This first callsgetUserById(long)
, and if the return isnull
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 aUser
known by Discord. Typically occurs when developers provide an incomplete id (cut short).
- Parameters:
id
- The id of the requestedUser
.- Returns:
RestAction
- Type:User
On request, gets the User with id matching provided id from Discord.- Throws:
IllegalStateException
- If there isn't any active shards.
-
getUserByTag
Searches for the first user that has the matching Discord Tag.
Format has to be in the formUsername#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 will only check cached users!
This only checks users that are known to the currently logged in account (shards). If a user exists with the tag that is not available in the
User-Cache
it will not be detected.
Currently Discord does not offer a way to retrieve a user by their discord tag.- Parameters:
tag
- The Discord Tag in the formatUsername#Discriminator
- Returns:
- The
User
for the discord tag or null if no user has the provided tag - Throws:
IllegalArgumentException
- If the provided tag is null or not in the described format
-
getUserByTag
Searches for the first user that has the matching Discord Tag.
Format has to be in the formUsername#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 will only check cached users!
This only checks users that are known to the currently logged in account (shards). If a user exists with the tag that is not available in the
User-Cache
it will not be detected.
Currently Discord does not offer a way to retrieve a user by their discord tag.- Parameters:
username
- The name of the userdiscriminator
- The discriminator of the user- Returns:
- The
User
for the discord tag or null if no user has the provided tag - Throws:
IllegalArgumentException
- If the provided arguments are null or not in the described format
-
getPrivateChannelById
This returns thePrivateChannel
which has the same id as the one provided.
If there is no knownPrivateChannel
with an id that matches the provided one, then this will returnnull
.- Parameters:
id
- The id of thePrivateChannel
.- Returns:
- Possibly-null
PrivateChannel
with matching id.
-
getPrivateChannelById
This returns thePrivateChannel
which has the same id as the one provided.
If there is no knownPrivateChannel
with an id that matches the provided one, this will returnnull
.- Parameters:
id
- The id of thePrivateChannel
.- Returns:
- Possibly-null
PrivateChannel
with matching id. - Throws:
NumberFormatException
- If the providedid
cannot be parsed byLong.parseLong(String)
-
getPrivateChannelCache
SnowflakeCacheView
of all cachedPrivateChannels
visible to this ShardManager instance.- Returns:
SnowflakeCacheView
-
getPrivateChannels
An unmodifiable list of all knownPrivateChannels
.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
getPrivateChannelCache()
and use its more efficient versions of handling these values.- Returns:
- Possibly-empty list of all
PrivateChannels
.
-
getRoleById
Retrieves theRole
associated to the provided id.
This iterates over allGuilds
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
-
getRoleById
Retrieves theRole
associated to the provided id.
This iterates over allGuilds
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:
NumberFormatException
- If the providedid
cannot be parsed byLong.parseLong(String)
-
getRoleCache
UnifiedSnowflakeCacheView
of all cachedRoles
visible to this ShardManager instance.- Returns:
- Unified
SnowflakeCacheView
-
getRoles
AllRoles
this ShardManager instance can see.
This will iterate over eachGuild
retrieved fromgetGuilds()
and collect itsGuild.getRoles()
.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
getRoleCache()
and use its more efficient versions of handling these values.- Returns:
- Immutable List of all visible Roles
-
getRolesByName
Retrieves allRoles
visible to this ShardManager instance.
This simply filters the Roles returned bygetRoles()
with the provided name, either usingString.equals(Object)
orString.equalsIgnoreCase(String)
onRole.getName()
.- Parameters:
name
- The name for the RolesignoreCase
- Whether to useString.equalsIgnoreCase(String)
- Returns:
- Immutable List of all Roles matching the parameters provided.
-
getGuildChannelById
GetGuildChannel
for the provided ID.
This checks if any of the channel types in this guild have the provided ID and returns the first match.
To get more specific channel types you can use one of the following:- Parameters:
id
- The ID of the channel- Returns:
- The GuildChannel or null
- Throws:
IllegalArgumentException
- If the provided ID is nullNumberFormatException
- If the provided ID is not a snowflake
-
getGuildChannelById
GetGuildChannel
for the provided ID.
This checks if any of the channel types in this guild have the provided ID and returns the first match.
To get more specific channel types you can use one of the following:- Parameters:
id
- The ID of the channel- Returns:
- The GuildChannel or null
-
getGuildChannelById
GetGuildChannel
for the provided ID.
This is meant for systems that use a dynamicChannelType
and can profit from a simple function to get the channel instance. To get more specific channel types you can use one of the following:- Parameters:
type
- TheChannelType
id
- The ID of the channel- Returns:
- The GuildChannel or null
- Throws:
IllegalArgumentException
- If the provided ID is nullNumberFormatException
- If the provided ID is not a snowflakeIllegalArgumentException
- If the providedChannelType
is null
-
getGuildChannelById
GetGuildChannel
for the provided ID.
This is meant for systems that use a dynamicChannelType
and can profit from a simple function to get the channel instance. To get more specific channel types you can use one of the following:- Parameters:
type
- TheChannelType
id
- The ID of the channel- Returns:
- The GuildChannel or null
- Throws:
IllegalArgumentException
- If the providedChannelType
is null
-
getShardById
This returns theJDA
instance which has the same id as the one provided.
If there is no shard with an id that matches the provided one, this will returnnull
.- Parameters:
id
- The id of the shard.- Returns:
- The
JDA
instance with the given shardId ornull
if no shard has the given id
-
getShardById
This returns theJDA
instance which has the same id as the one provided.
If there is no shard with an id that matches the provided one, this will returnnull
.- Parameters:
id
- The id of the shard.- Returns:
- The
JDA
instance with the given shardId ornull
if no shard has the given id
-
getShardCache
UnifiedShardCacheView
of all cachedJDA
bound to this ShardManager instance.- Returns:
- Unified
ShardCacheView
-
getShards
Gets allJDA
instances bound to this ShardManager.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
getShardCache()
and use its more efficient versions of handling these values.- Returns:
- An immutable list of all managed
JDA
instances.
-
getStatus
This returns theJDA.Status
of the shard which has the same id as the one provided.
If there is no shard with an id that matches the provided one, this will returnnull
.- Parameters:
shardId
- The id of the shard.- Returns:
- The
JDA.Status
of the shard with the given shardId ornull
if no shard has the given id
-
getStatuses
Gets the currentStatus
of all shards.- Returns:
- All current shard statuses.
-
getTextChannelById
This returns theTextChannel
which has the same id as the one provided.
If there is no knownTextChannel
with an id that matches the provided one, this will returnnull
.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 anyTextChannel
that you don't have thePermission.VIEW_CHANNEL
permission in.- Parameters:
id
- The id of theTextChannel
.- Returns:
- Possibly-null
TextChannel
with matching id.
-
getTextChannelById
This returns theTextChannel
which has the same id as the one provided.
If there is no knownTextChannel
with an id that matches the provided one, this will returnnull
.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 anyTextChannel
that you don't have thePermission.VIEW_CHANNEL
permission in.- Parameters:
id
- The id of theTextChannel
.- Returns:
- Possibly-null
TextChannel
with matching id.
-
getTextChannelCache
SnowflakeCacheView
of all cachedTextChannels
visible to this ShardManager instance.- Returns:
SnowflakeCacheView
-
getTextChannels
An unmodifiable List of allTextChannels
of all connectedGuilds
.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 anyTextChannel
that you don't have thePermission.VIEW_CHANNEL
permission in.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
getTextChannelCache()
and use its more efficient versions of handling these values.- Returns:
- Possibly-empty list of all known
TextChannels
.
-
getStoreChannelById
This returns theStoreChannel
which has the same id as the one provided.
If there is no knownStoreChannel
with an id that matches the provided one, this will returnnull
.- Parameters:
id
- The id of theStoreChannel
.- Returns:
- Possibly-null
StoreChannel
with matching id.
-
getStoreChannelById
This returns theStoreChannel
which has the same id as the one provided.
If there is no knownStoreChannel
with an id that matches the provided one, this will returnnull
.- Parameters:
id
- The id of theStoreChannel
.- Returns:
- Possibly-null
StoreChannel
with matching id.
-
getStoreChannelCache
SnowflakeCacheView
of all cachedStoreChannels
visible to this ShardManager instance.- Returns:
SnowflakeCacheView
-
getStoreChannels
An unmodifiable List of allStoreChannels
of all connectedGuilds
.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
getStoreChannelCache()
and use its more efficient versions of handling these values.- Returns:
- Possibly-empty list of all known
StoreChannels
.
-
getUserById
This returns theUser
which has the same id as the one provided.
If there is no visible user with an id that matches the provided one, this will returnnull
. -
getUserById
This returns theUser
which has the same id as the one provided.
If there is no visible user with an id that matches the provided one, this will returnnull
. -
getUserCache
SnowflakeCacheView
of all cachedUsers
visible to this ShardManager instance.- Returns:
SnowflakeCacheView
-
getUsers
An unmodifiable list of allUsers
that share aGuild
with the currently logged in account.
This list will never contain duplicates and represents allUsers
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.
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
getUserCache()
and use its more efficient versions of handling these values.- Returns:
- List of all
Users
that are visible to JDA.
-
getVoiceChannelById
This returns theVoiceChannel
which has the same id as the one provided.
If there is no knownVoiceChannel
with an id that matches the provided one, this will returnnull
.- Parameters:
id
- The id of theVoiceChannel
.- Returns:
- Possibly-null
VoiceChannel
with matching id.
-
getVoiceChannelById
This returns theVoiceChannel
which has the same id as the one provided.
If there is no knownVoiceChannel
with an id that matches the provided one, this will returnnull
.- Parameters:
id
- The id of theVoiceChannel
.- Returns:
- Possibly-null
VoiceChannel
with matching id.
-
getVoiceChannelCache
SnowflakeCacheView
of all cachedVoiceChannels
visible to this ShardManager instance.- Returns:
SnowflakeCacheView
-
getVoiceChannels
An unmodifiable list of allVoiceChannels
of all connectedGuilds
.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
getVoiceChannelCache()
and use its more efficient versions of handling these values.- Returns:
- Possible-empty list of all known
VoiceChannels
.
-
restart
void restart()Restarts all shards, shutting old ones down first.As all shards need to connect to discord again this will take equally long as the startup of a new ShardManager (using the 5000ms + backoff as delay between starting new JDA instances).
- Throws:
RejectedExecutionException
- Ifshutdown()
has already been invoked
-
restart
void restart(int id) Restarts the shards with the given id only.
If there is no shard with the given Id, this method acts likestart(int)
.- Parameters:
id
- The id of the target shard- Throws:
IllegalArgumentException
- If shardId is negative or higher than maxShardIdRejectedExecutionException
- Ifshutdown()
has already been invoked
-
setActivity
Sets theActivity
for all shards.
An Activity can be retrieved viaActivity.playing(String)
. For streams you provide a valid streaming url as second parameter.This will also change the activity for shards that are created in the future.
- Parameters:
activity
- AActivity
instance or null to reset- See Also:
-
setActivityProvider
Sets provider that provider theActivity
for all shards.
A Activity can be retrieved viaActivity.playing(String)
. For streams you provide a valid streaming url as second parameter.This will also change the provider for shards that are created in the future.
- Parameters:
activityProvider
- Provider for anActivity
instance or null to reset- See Also:
-
setIdle
default void setIdle(boolean idle) Sets whether all instances should be marked as afk or notThis is relevant to client accounts to monitor whether new messages should trigger mobile push-notifications.
This will also change the value for shards that are created in the future.
- Parameters:
idle
- boolean
-
setIdleProvider
Sets the provider that decides for all shards whether they should be marked as afk or not.This will also change the provider for shards that are created in the future.
- Parameters:
idleProvider
- Provider for a boolean
-
setPresence
Sets theOnlineStatus
andActivity
for all shards.This will also change the status for shards that are created in the future.
- Parameters:
status
- TheOnlineStatus
to be used (OFFLINE/null -> INVISIBLE)activity
- AActivity
instance or null to reset- Throws:
IllegalArgumentException
- If the provided OnlineStatus isUNKNOWN
- See Also:
-
setPresenceProvider
default void setPresenceProvider(@Nullable IntFunction<OnlineStatus> statusProvider, @Nullable IntFunction<? extends Activity> activityProvider) Sets the provider that provides theOnlineStatus
andActivity
for all shards.This will also change the status for shards that are created in the future.
- Parameters:
statusProvider
- TheOnlineStatus
to be used (OFFLINE/null -> INVISIBLE)activityProvider
- AActivity
instance or null to reset- Throws:
IllegalArgumentException
- If the provided OnlineStatus isUNKNOWN
- See Also:
-
setStatus
Sets theOnlineStatus
for all shards.This will also change the status for shards that are created in the future.
- Parameters:
status
- TheOnlineStatus
to be used (OFFLINE/null -> INVISIBLE)- Throws:
IllegalArgumentException
- If the provided OnlineStatus isUNKNOWN
-
setStatusProvider
Sets the provider that provides theOnlineStatus
for all shards.This will also change the provider for shards that are created in the future.
- Parameters:
statusProvider
- TheOnlineStatus
to be used (OFFLINE/null -> INVISIBLE)- Throws:
IllegalArgumentException
- If the provided OnlineStatus isUNKNOWN
-
shutdown
void shutdown()Shuts down all JDA shards, closing all their connections. After this method has been called the ShardManager instance can not be used anymore.
This will shutdown the internal queue worker for (re-)starts of shards. This meansrestart(int)
,restart()
, andstart(int)
will throwRejectedExecutionException
.This will interrupt the default JDA event thread, due to the gateway connection being interrupted.
-
shutdown
void shutdown(int shardId) Shuts down the shard with the given id only.
If there is no shard with the given id, this will do nothing.- Parameters:
shardId
- The id of the shard that should be stopped
-
start
void start(int shardId) Adds a new shard with the given id to this ShardManager and starts it.- Parameters:
shardId
- The id of the shard that should be started- Throws:
RejectedExecutionException
- Ifshutdown()
has already been invoked
-
login
Initializes and starts all shards. This should only be called once.- Throws:
LoginException
- If the provided token is invalid.
-