Interface ShardManager
-
- All Known Implementing Classes:
DefaultShardManager
public interface ShardManager
This class acts as a manager for multiple shards. It contains several methods to make your life with sharding easier.
Custom implementations my not support all methods and throwUnsupportedOperationExceptions
instead.- Since:
- 3.4
- Author:
- Aljoscha Grebe
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
addEventListener(java.lang.Object... listeners)
Adds all provided listeners to the event-listeners that will be used to handle events.default void
addEventListeners(java.util.function.IntFunction<java.lang.Object> eventListenerProvider)
Adds listeners provided by the listener provider to each shard to the event-listeners that will be used to handle events.default RestAction<ApplicationInfo>
getApplicationInfo()
Used to access Bot specific functions like OAuth information.default double
getAveragePing()
The average time in milliseconds between all shards that discord took to respond to our last heartbeat.default java.util.List<Category>
getCategories()
Gets allCategories
visible to the currently logged in account.default java.util.List<Category>
getCategoriesByName(java.lang.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
getCategoryById(java.lang.String id)
Gets theCategory
that matches the provided id.default SnowflakeCacheView<Category>
getCategoryCache()
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(java.lang.String id)
Retrieves an emote matching the specifiedid
if one is available in our cache.default SnowflakeCacheView<Emote>
getEmoteCache()
UnifiedSnowflakeCacheView
of all cachedEmotes
visible to this ShardManager instance.default java.util.List<Emote>
getEmotes()
A collection of all to us known emotes (managed/restricted included).default java.util.List<Emote>
getEmotesByName(java.lang.String name, boolean ignoreCase)
An unmodifiable list of allEmotes
that have the same name as the one provided.default Guild
getGuildById(long id)
This returns theGuild
which has the same id as the one provided.default Guild
getGuildById(java.lang.String id)
This returns theGuild
which has the same id as the one provided.default SnowflakeCacheView<Guild>
getGuildCache()
SnowflakeCacheView
of all cachedGuilds
visible to this ShardManager instance.default java.util.List<Guild>
getGuilds()
An unmodifiable List of allGuilds
that the logged account is connected to.default java.util.List<Guild>
getGuildsByName(java.lang.String name, boolean ignoreCase)
An unmodifiable list of allGuilds
that have the same name as the one provided.default java.util.List<Guild>
getMutualGuilds(java.util.Collection<User> users)
Gets allGuilds
that contain all given users as their members.default java.util.List<Guild>
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
getPrivateChannelById(java.lang.String id)
This returns thePrivateChannel
which has the same id as the one provided.default SnowflakeCacheView<PrivateChannel>
getPrivateChannelCache()
SnowflakeCacheView
of all cachedPrivateChannels
visible to this ShardManager instance.default java.util.List<PrivateChannel>
getPrivateChannels()
An unmodifiable list of all knownPrivateChannels
.default Role
getRoleById(long id)
Retrieves theRole
associated to the provided id.default Role
getRoleById(java.lang.String id)
Retrieves theRole
associated to the provided id.default SnowflakeCacheView<Role>
getRoleCache()
UnifiedSnowflakeCacheView
of all cachedRoles
visible to this ShardManager instance.default java.util.List<Role>
getRoles()
AllRoles
this ShardManager instance can see.default java.util.List<Role>
getRolesByName(java.lang.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(java.lang.String id)
This returns theJDA
instance which has the same id as the one provided.ShardCacheView
getShardCache()
UnifiedShardCacheView
of all cachedJDA
bound to this ShardManager instance.default java.util.List<JDA>
getShards()
Gets allJDA
instances bound to this ShardManager.int
getShardsQueued()
Returns the amount of shards queued for (re)connecting.default int
getShardsRunning()
Returns the amount of running shards.default int
getShardsTotal()
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 java.util.Map<JDA,JDA.Status>
getStatuses()
Gets the currentStatus
of all shards.default TextChannel
getTextChannelById(long id)
This returns theTextChannel
which has the same id as the one provided.default TextChannel
getTextChannelById(java.lang.String id)
This returns theTextChannel
which has the same id as the one provided.default SnowflakeCacheView<TextChannel>
getTextChannelCache()
SnowflakeCacheView
of all cachedTextChannels
visible to this ShardManager instance.default java.util.List<TextChannel>
getTextChannels()
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(java.lang.String id)
This returns theUser
which has the same id as the one provided.default SnowflakeCacheView<User>
getUserCache()
SnowflakeCacheView
of all cachedUsers
visible to this ShardManager instance.default java.util.List<User>
getUsers()
default VoiceChannel
getVoiceChannelById(long id)
This returns theVoiceChannel
which has the same id as the one provided.default VoiceChannel
getVoiceChannelById(java.lang.String id)
This returns theVoiceChannel
which has the same id as the one provided.default SnowflakeCacheView<VoiceChannel>
getVoiceChannelCache()
SnowflakeCacheView
of all cachedVoiceChannels
visible to this ShardManager instance.default java.util.List<VoiceChannel>
getVoiceChannels()
An unmodifiable list of allVoiceChannels
of all connectedGuilds
.default void
removeEventListener(java.lang.Object... listeners)
Removes all provided listeners from the event-listeners and no longer uses them to handle events.default void
removeEventListenerProvider(java.util.function.IntFunction<java.lang.Object> eventListenerProvider)
Remove a listener provider.default void
removeEventListeners(java.util.function.IntFunction<java.util.Collection<java.lang.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<User>
retrieveUserById(long id)
Attempts to retrieve aUser
object based on the provided id.default RestAction<User>
retrieveUserById(java.lang.String id)
Attempts to retrieve aUser
object based on the provided id.default void
setGame(Game game)
Sets theGame
for all shards.default void
setGameProvider(java.util.function.IntFunction<? extends Game> gameProvider)
Sets provider that provider theGame
for all shards.default void
setIdle(boolean idle)
Sets whether all instances should be marked as afk or notdefault void
setIdleProvider(java.util.function.IntFunction<java.lang.Boolean> idleProvider)
Sets the provider that decides for all shards whether they should be marked as afk or not.default void
setStatus(OnlineStatus status)
Sets theOnlineStatus
for all shards.default void
setStatusProvider(java.util.function.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 Detail
-
addEventListener
default void addEventListener(java.lang.Object... listeners)
Adds all provided listeners to the event-listeners that will be used to handle events.Note: when using the
InterfacedEventListener
(default), given listener must be instance ofEventListener
!- Parameters:
listeners
- The listener(s) which will react to events.- Throws:
java.lang.IllegalArgumentException
- If either listeners or one of it's objects isnull
.
-
removeEventListener
default 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 isnull
.
-
addEventListeners
default void addEventListeners(java.util.function.IntFunction<java.lang.Object> eventListenerProvider)
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), given listener must be instance ofEventListener
!- Parameters:
eventListenerProvider
- The provider of listener(s) which will react to events.- Throws:
java.lang.IllegalArgumentException
- If the provided listener provider or any of the listeners or provides arenull
.
-
removeEventListeners
default void removeEventListeners(java.util.function.IntFunction<java.util.Collection<java.lang.Object>> eventListenerProvider)
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:
java.lang.IllegalArgumentException
- If the provided event listeners provider isnull
.
-
removeEventListenerProvider
default void removeEventListenerProvider(java.util.function.IntFunction<java.lang.Object> eventListenerProvider)
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:
java.lang.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.
-
getApplicationInfo
default RestAction<ApplicationInfo> getApplicationInfo()
Used to access Bot specific functions like OAuth information.- Returns:
- The
JDABot
registry for this instance of JDA. - Throws:
java.lang.IllegalStateException
- If there is no running shard
-
getAveragePing
default double getAveragePing()
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 is no shard running this wil 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
default java.util.List<Category> getCategories()
Gets allCategories
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 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:
java.lang.IllegalArgumentException
- If the provided name isnull
-
getCategoryById
default Category getCategoryById(long id)
- Parameters:
id
- The snowflake ID of the wanted Category- Returns:
- Possibly-null
Category
for the provided ID.
-
getCategoryById
default Category getCategoryById(java.lang.String id)
- 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 validlong
-
getCategoryCache
default SnowflakeCacheView<Category> getCategoryCache()
SnowflakeCacheView
of all cachedCategories
visible to this ShardManager instance.- Returns:
SnowflakeCacheView
-
getEmoteById
default Emote getEmoteById(long id)
Retrieves an emote matching the specifiedid
if one is available in our cache.Unicode emojis are not included as
Emote
!
-
getEmoteById
default Emote getEmoteById(java.lang.String id)
Retrieves an emote matching the specifiedid
if one is available in our cache.Unicode emojis are not included as
Emote
!
-
getEmoteCache
default SnowflakeCacheView<Emote> getEmoteCache()
UnifiedSnowflakeCacheView
of all cachedEmotes
visible to this ShardManager instance.- Returns:
- Unified
SnowflakeCacheView
-
getEmotes
default java.util.List<Emote> getEmotes()
A collection of all to us 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.core.entities.Member)
orEmote.canInteract(net.dv8tion.jda.core.entities.User, net.dv8tion.jda.core.entities.MessageChannel)
Unicode emojis are not included as
Emote
!- Returns:
- An immutable list of Emotes (which may or may not be available to usage).
-
getEmotesByName
default java.util.List<Emote> getEmotesByName(java.lang.String name, boolean ignoreCase)
An unmodifiable list of allEmotes
that have the same name as the one provided.
If there are noEmotes
with the provided name, then this returns an empty list.Unicode emojis are not included as
Emote
!- Parameters:
name
- The name of the requestedEmotes
.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
default Guild getGuildById(long id)
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, then this returnsnull
.
-
getGuildById
default Guild getGuildById(java.lang.String id)
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, then this returnsnull
.
-
getGuildsByName
default java.util.List<Guild> getGuildsByName(java.lang.String name, boolean ignoreCase)
An unmodifiable list of allGuilds
that have the same name as the one provided.
If there are noGuilds
with the provided name, then this returns 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
default SnowflakeCacheView<Guild> getGuildCache()
SnowflakeCacheView
of all cachedGuilds
visible to this ShardManager instance.- Returns:
SnowflakeCacheView
-
getGuilds
default java.util.List<Guild> 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.- Returns:
- Possibly-empty list of all the
Guilds
that this account is connected to.
-
getMutualGuilds
default java.util.List<Guild> getMutualGuilds(java.util.Collection<User> users)
Gets allGuilds
that contain all given users as their members.
-
getMutualGuilds
default java.util.List<Guild> getMutualGuilds(User... users)
Gets allGuilds
that contain all given users as their members.
-
retrieveUserById
@CheckReturnValue default RestAction<User> retrieveUserById(java.lang.String id)
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:
java.lang.IllegalArgumentException
- If the provided id String is not a valid snowflake.java.lang.IllegalStateException
- If there isn't any active shards.
-
retrieveUserById
@CheckReturnValue default RestAction<User> retrieveUserById(long id)
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:
java.lang.IllegalStateException
- If there isn't any active shards.
-
getPrivateChannelById
default PrivateChannel getPrivateChannelById(long id)
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 returnsnull
.- Parameters:
id
- The id of thePrivateChannel
.- Returns:
- Possibly-null
PrivateChannel
with matching id.
-
getPrivateChannelById
default PrivateChannel getPrivateChannelById(java.lang.String id)
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 returnsnull
.- Parameters:
id
- The id of thePrivateChannel
.- Returns:
- Possibly-null
PrivateChannel
with matching id. - Throws:
java.lang.NumberFormatException
- If the providedid
cannot be parsed byLong.parseLong(String)
-
getPrivateChannelCache
default SnowflakeCacheView<PrivateChannel> getPrivateChannelCache()
SnowflakeCacheView
of all cachedPrivateChannels
visible to this ShardManager instance.- Returns:
SnowflakeCacheView
-
getPrivateChannels
default java.util.List<PrivateChannel> getPrivateChannels()
An unmodifiable list of all knownPrivateChannels
.- Returns:
- Possibly-empty list of all
PrivateChannels
.
-
getRoleById
default Role getRoleById(long id)
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
default Role getRoleById(java.lang.String id)
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:
java.lang.NumberFormatException
- If the providedid
cannot be parsed byLong.parseLong(String)
-
getRoleCache
default SnowflakeCacheView<Role> getRoleCache()
UnifiedSnowflakeCacheView
of all cachedRoles
visible to this ShardManager instance.- Returns:
- Unified
SnowflakeCacheView
-
getRoles
default java.util.List<Role> getRoles()
AllRoles
this ShardManager instance can see.
This will iterate over eachGuild
retrieved fromgetGuilds()
and collect itsGuild.getRoles()
.- Returns:
- Immutable List of all visible Roles
-
getRolesByName
default java.util.List<Role> getRolesByName(java.lang.String name, boolean ignoreCase)
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.
-
getShardById
default JDA getShardById(int id)
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, then this returnsnull
.- Parameters:
id
- The id of the shard.- Returns:
- The
JDA
instance with the given shardId ornull
if no shard has the given id
-
getShardById
default JDA getShardById(java.lang.String id)
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, then this returnsnull
.- Parameters:
id
- The id of the shard.- Returns:
- The
JDA
instance with the given shardId ornull
if no shard has the given id
-
getShardCache
ShardCacheView getShardCache()
UnifiedShardCacheView
of all cachedJDA
bound to this ShardManager instance.- Returns:
- Unified
ShardCacheView
-
getShards
default java.util.List<JDA> getShards()
Gets allJDA
instances bound to this ShardManager.- Returns:
- An immutable list of all managed
JDA
instances.
-
getStatus
default JDA.Status getStatus(int shardId)
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, then this returnsnull
.- 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
default java.util.Map<JDA,JDA.Status> getStatuses()
Gets the currentStatus
of all shards.- Returns:
- All current shard statuses.
-
getTextChannelById
default TextChannel getTextChannelById(long id)
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, then this returnsnull
.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.MESSAGE_READ
permission in.- Parameters:
id
- The id of theTextChannel
.- Returns:
- Possibly-null
TextChannel
with matching id.
-
getTextChannelById
default TextChannel getTextChannelById(java.lang.String id)
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, then this returnsnull
.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.MESSAGE_READ
permission in.- Parameters:
id
- The id of theTextChannel
.- Returns:
- Possibly-null
TextChannel
with matching id.
-
getTextChannelCache
default SnowflakeCacheView<TextChannel> getTextChannelCache()
SnowflakeCacheView
of all cachedTextChannels
visible to this ShardManager instance.- Returns:
SnowflakeCacheView
-
getTextChannels
default java.util.List<TextChannel> 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.MESSAGE_READ
permission in.- Returns:
- Possibly-empty list of all known
TextChannels
.
-
getUserById
default User getUserById(long id)
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 returnsnull
.
-
getUserById
default User getUserById(java.lang.String id)
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 returnsnull
.
-
getUserCache
default SnowflakeCacheView<User> getUserCache()
SnowflakeCacheView
of all cachedUsers
visible to this ShardManager instance.- Returns:
SnowflakeCacheView
-
getUsers
default java.util.List<User> 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.
- Returns:
- List of all
Users
that are visible to JDA.
-
getVoiceChannelById
default VoiceChannel getVoiceChannelById(long id)
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, then this returnsnull
.- Parameters:
id
- The id of theVoiceChannel
.- Returns:
- Possibly-null
VoiceChannel
with matching id.
-
getVoiceChannelById
default VoiceChannel getVoiceChannelById(java.lang.String id)
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, then this returnsnull
.- Parameters:
id
- The id of theVoiceChannel
.- Returns:
- Possibly-null
VoiceChannel
with matching id.
-
getVoiceChannelCache
default SnowflakeCacheView<VoiceChannel> getVoiceChannelCache()
SnowflakeCacheView
of all cachedVoiceChannels
visible to this ShardManager instance.- Returns:
SnowflakeCacheView
-
getVoiceChannels
default java.util.List<VoiceChannel> getVoiceChannels()
An unmodifiable list of allVoiceChannels
of all connectedGuilds
.- 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).
-
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:
java.lang.IllegalArgumentException
- if shardId is negative or higher than maxShardId
-
setGame
default void setGame(Game game)
Sets theGame
for all shards.
A Game can be retrieved viaGame.playing(String)
. For streams you provide a valid streaming url as second parameter.This will also change the game for shards that are created in the future.
- Parameters:
game
- AGame
instance or null to reset- See Also:
Game.playing(String)
,Game.streaming(String, String)
-
setGameProvider
default void setGameProvider(java.util.function.IntFunction<? extends Game> gameProvider)
Sets provider that provider theGame
for all shards.
A Game can be retrieved viaGame.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:
gameProvider
- AGame
instance or null to reset- See Also:
Game.playing(String)
,Game.streaming(String, String)
-
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
default void setIdleProvider(java.util.function.IntFunction<java.lang.Boolean> idleProvider)
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
- boolean
-
setStatus
default void setStatus(OnlineStatus status)
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:
java.lang.IllegalArgumentException
- if the provided OnlineStatus isUNKNOWN
-
setStatusProvider
default void setStatusProvider(java.util.function.IntFunction<OnlineStatus> statusProvider)
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:
java.lang.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.
-
shutdown
void shutdown(int shardId)
Shuts down the shard with the given id only.
This does nothing if there is no shard with the given id.- 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
-
-