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.- See Also:
JDABuilder
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
JDA.ShardInfo
Represents the information used to create this shard.static class
JDA.Status
Represents the connection status of JDA and its Main WebSocket.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
addEventListener(java.lang.Object... listeners)
Adds all provided listeners to the event-listeners that will be used to handle events.default JDA
awaitReady()
This method will block until JDA has reached the statusJDA.Status.CONNECTED
.default JDA
awaitStatus(JDA.Status status)
This method will block until JDA has reached the specified connection status.JDA
awaitStatus(JDA.Status status, JDA.Status... failOn)
This method will block until JDA has reached the specified connection status.int
cancelRequests()
Cancels all currently scheduledRestAction
requests.GuildAction
createGuild(java.lang.String name)
Constructs a newGuild
with the specified name
Use the returnedGuildAction
to provide further details and settings for the resulting Guild!RestAction<java.lang.Void>
createGuildFromTemplate(java.lang.String code, java.lang.String name, Icon icon)
Constructs a newGuild
from the specified template code.default RestAction<java.lang.Void>
deleteCommandById(long commandId)
Delete the global command for this id.RestAction<java.lang.Void>
deleteCommandById(java.lang.String commandId)
Delete the global command for this id.default CommandEditAction
editCommandById(long id)
Edit an existing global command by id.CommandEditAction
editCommandById(java.lang.String id)
Edit an existing global command by id.AccountType
getAccountType()
TheAccountType
of the currently logged in account.CacheView<AudioManager>
getAudioManagerCache()
CacheView
of all cachedAudioManagers
created for this JDA instance.default java.util.List<AudioManager>
getAudioManagers()
Immutable list of all createdAudioManagers
for this JDA instance!java.util.EnumSet<CacheFlag>
getCacheFlags()
Thecache flags
that have been enabled for this JDA session.java.util.concurrent.ExecutorService
getCallbackPool()
ExecutorService
used to handleRestAction
callbacks and completions.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.SnowflakeCacheView<Category>
getCategoryCache()
SnowflakeCacheView
of all cachedCategories
visible to this JDA session.DirectAudioController
getDirectAudioController()
Direct access to audio (dis-)connect requests.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.SnowflakeCacheView<Emote>
getEmoteCache()
UnifiedSnowflakeCacheView
of all cachedEmotes
visible to this JDA session.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.IEventManager
getEventManager()
The EventManager used by this JDA instance.java.util.EnumSet<GatewayIntent>
getGatewayIntents()
TheGatewayIntents
for this JDA session.long
getGatewayPing()
The time in milliseconds that discord took to respond to our last heartbeat
This roughly represents the WebSocket ping of this sessionjava.util.concurrent.ScheduledExecutorService
getGatewayPool()
ScheduledExecutorService
used to send WebSocket messages to discord.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.SnowflakeCacheView<Guild>
getGuildCache()
SnowflakeCacheView
of all cachedGuilds
visible to this JDA session.default GuildChannel
getGuildChannelById(long id)
GetGuildChannel
for the provided ID.default GuildChannel
getGuildChannelById(java.lang.String id)
GetGuildChannel
for the provided ID.default GuildChannel
getGuildChannelById(ChannelType type, long id)
GetGuildChannel
for the provided ID.default GuildChannel
getGuildChannelById(ChannelType type, java.lang.String id)
GetGuildChannel
for the provided ID.default java.util.List<Guild>
getGuilds()
An immutable List of allGuilds
that the logged account is connected to.default java.util.List<Guild>
getGuildsByName(java.lang.String name, boolean ignoreCase)
An immutable list of allGuilds
that have the same name as the one provided.OkHttpClient
getHttpClient()
TheOkHttpClient
used for handling http requests fromRestActions
.java.lang.String
getInviteUrl(java.util.Collection<Permission> permissions)
Creates an authorization invite url for the currently logged in Bot-Account.java.lang.String
getInviteUrl(Permission... permissions)
Creates an authorization invite url for the currently logged in Bot-Account.int
getMaxReconnectDelay()
This value is the maximum amount of time, in seconds, that JDA will wait between reconnect attempts.java.util.List<Guild>
getMutualGuilds(java.util.Collection<User> users)
Gets allGuilds
that contain all given users as their members.java.util.List<Guild>
getMutualGuilds(User... users)
Gets allGuilds
that contain all given users as their members.Presence
getPresence()
ThePresence
controller for the current session.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.SnowflakeCacheView<PrivateChannel>
getPrivateChannelCache()
SnowflakeCacheView
of all cachedPrivateChannels
visible to this JDA session.default java.util.List<PrivateChannel>
getPrivateChannels()
An unmodifiable list of all knownPrivateChannels
.java.util.concurrent.ScheduledExecutorService
getRateLimitPool()
ScheduledExecutorService
used to handle rate-limits forRestAction
executions.java.util.List<java.lang.Object>
getRegisteredListeners()
Immutable List of Objects that have been registered as EventListeners.long
getResponseTotal()
This value is the total amount of JSON responses that discord has sent.default RestAction<java.lang.Long>
getRestPing()
The time in milliseconds that discord took to respond to a REST request.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.SnowflakeCacheView<Role>
getRoleCache()
UnifiedSnowflakeCacheView
of all cachedRoles
visible to this JDA session.default java.util.List<Role>
getRoles()
AllRoles
this JDA instance can see.default java.util.List<Role>
getRolesByName(java.lang.String name, boolean ignoreCase)
Retrieves allRoles
visible to this JDA instance.SelfUser
getSelfUser()
Returns the currently logged in account represented bySelfUser
.JDA.ShardInfo
getShardInfo()
The shard information used when creating this instance of JDA.ShardManager
getShardManager()
Returns theShardManager
that manages this JDA instances or null if this instance is not managed by anyShardManager
.default StageChannel
getStageChannelById(long id)
This returns theStageChannel
which has the same id as the one provided.default StageChannel
getStageChannelById(java.lang.String id)
This returns theStageChannel
which has the same id as the one provided.default java.util.List<StageChannel>
getStageChannels()
An unmodifiable list of allStageChannels
of all connectedGuilds
.default java.util.List<StageChannel>
getStageChannelsByName(java.lang.String name, boolean ignoreCase)
An unmodifiable list of allStageChannels
that have the same name as the one provided.JDA.Status
getStatus()
Gets the currentStatus
of the JDA instance.default StoreChannel
getStoreChannelById(long id)
Gets aStoreChannel
that has the same id as the one provided.default StoreChannel
getStoreChannelById(java.lang.String id)
Gets aStoreChannel
that has the same id as the one provided.SnowflakeCacheView<StoreChannel>
getStoreChannelCache()
SnowflakeCacheView
of all cachedStoreChannels
visible to this JDA session.default java.util.List<StoreChannel>
getStoreChannels()
Gets allStoreChannels
of all connectedGuilds
.default java.util.List<StoreChannel>
getStoreChannelsByName(java.lang.String name, boolean ignoreCase)
An unmodifiable list of allStoreChannels
that have the same name as the one provided.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.SnowflakeCacheView<TextChannel>
getTextChannelCache()
SnowflakeCacheView
of all cachedTextChannels
visible to this JDA session.default java.util.List<TextChannel>
getTextChannels()
An unmodifiable List of allTextChannels
of all connectedGuilds
.default java.util.List<TextChannel>
getTextChannelsByName(java.lang.String name, boolean ignoreCase)
An unmodifiable list of allTextChannels
that have the same name as the one provided.java.lang.String
getToken()
The login token that is currently being used for Discord authentication.java.util.Set<java.lang.String>
getUnavailableGuilds()
Set ofGuild
IDs for guilds that were marked unavailable by the gateway.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 User
getUserByTag(java.lang.String tag)
Searches for a user that has the matching Discord Tag.default User
getUserByTag(java.lang.String username, java.lang.String discriminator)
Searches for a user that has the matching Discord Tag.SnowflakeCacheView<User>
getUserCache()
SnowflakeCacheView
of all cachedUsers
visible to this JDA session.default java.util.List<User>
getUsers()
default java.util.List<User>
getUsersByName(java.lang.String name, boolean ignoreCase)
This immutable returns allUsers
that have the same username as the one provided.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.SnowflakeCacheView<VoiceChannel>
getVoiceChannelCache()
SnowflakeCacheView
of all cachedVoiceChannels
visible to this JDA session.default java.util.List<VoiceChannel>
getVoiceChannels()
An unmodifiable list of allVoiceChannels
of all connectedGuilds
.default java.util.List<VoiceChannel>
getVoiceChannelsByName(java.lang.String name, boolean ignoreCase)
An unmodifiable list of allVoiceChannels
that have the same name as the one provided.default AuditableRestAction<java.lang.Integer>
installAuxiliaryPort()
Installs an auxiliary port for audio transfer.boolean
isAutoReconnect()
USed to determine whether or not autoReconnect is enabled for JDA.boolean
isBulkDeleteSplittingEnabled()
Used to determine if JDA will process MESSAGE_DELETE_BULK messages received from Discord as a singleMessageBulkDeleteEvent
or split the deleted messages up and fire multipleMessageDeleteEvents
, one for each deleted message.boolean
isUnavailable(long guildId)
Whether the guild is unavailable.RestAction<PrivateChannel>
openPrivateChannelById(long userId)
Opens aPrivateChannel
with the provided user by id.default RestAction<PrivateChannel>
openPrivateChannelById(java.lang.String userId)
Opens aPrivateChannel
with the provided user by id.void
removeEventListener(java.lang.Object... listeners)
Removes all provided listeners from the event-listeners and no longer uses them to handle events.RestAction<ApplicationInfo>
retrieveApplicationInfo()
Retrieves theApplicationInfo
for the application that owns the logged in Bot-Account.default RestAction<Command>
retrieveCommandById(long id)
Retrieves the existingCommand
instance by id.RestAction<Command>
retrieveCommandById(java.lang.String id)
Retrieves the existingCommand
instance by id.RestAction<java.util.List<Command>>
retrieveCommands()
Retrieves the list of global commands.default RestAction<User>
retrieveUserById(long id)
Attempts to retrieve aUser
object based on the provided id.RestAction<User>
retrieveUserById(long id, boolean update)
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 RestAction<User>
retrieveUserById(java.lang.String id, boolean update)
Attempts to retrieve aUser
object based on the provided id.default RestAction<Webhook>
retrieveWebhookById(long webhookId)
Retrieves aWebhook
by its id.RestAction<Webhook>
retrieveWebhookById(java.lang.String webhookId)
Retrieves aWebhook
by its id.void
setAutoReconnect(boolean reconnect)
Sets whether or not JDA should try to automatically reconnect if a connection-error is encountered.void
setEventManager(IEventManager manager)
Changes the internal EventManager.void
setRequestTimeoutRetry(boolean retryOnTimeout)
Whether the Requester should retry when aSocketTimeoutException
occurs.default JDA
setRequiredScopes(java.lang.String... scopes)
Configures the required scopes applied to thegetInviteUrl(Permission...)
and similar methods.JDA
setRequiredScopes(java.util.Collection<java.lang.String> scopes)
Configures the required scopes applied to thegetInviteUrl(Permission...)
and similar methods.void
shutdown()
Shuts down this JDA instance, closing all its connections.void
shutdownNow()
Shuts down this JDA instance instantly, closing all its connections.boolean
unloadUser(long userId)
Attempts to remove the user with the provided id from the cache.CommandListUpdateAction
updateCommands()
Configures the complete list of global commands.default CommandCreateAction
upsertCommand(java.lang.String name, java.lang.String description)
Creates or updates a global command.CommandCreateAction
upsertCommand(CommandData command)
Creates or updates a global command.
-
-
-
Method Detail
-
getStatus
@Nonnull JDA.Status getStatus()
Gets the currentStatus
of the JDA instance.- Returns:
- Current JDA status.
-
getGatewayIntents
@Nonnull java.util.EnumSet<GatewayIntent> getGatewayIntents()
TheGatewayIntents
for this JDA session.- Returns:
EnumSet
of active gateway intents
-
getCacheFlags
@Nonnull java.util.EnumSet<CacheFlag> getCacheFlags()
Thecache flags
that have been enabled for this JDA session.- Returns:
- Copy of the EnumSet of cache flags for this session
-
unloadUser
boolean unloadUser(long userId)
Attempts to remove the user with the provided id from the cache.
If you attempt to remove theSelfUser
this will simply returnfalse
.This should be used by an implementation of
MemberCachePolicy
as an upstream request to remove a member.- Parameters:
userId
- The target user id- Returns:
- True, if the cache was changed
-
getGatewayPing
long getGatewayPing()
The time in milliseconds that discord took to respond to our last heartbeat
This roughly represents the WebSocket ping of this sessionRestAction
request times do not correlate to this value!The
GatewayPingEvent
indicates an update to this value.- Returns:
- time in milliseconds between heartbeat and the heartbeat ack response
- See Also:
Getting RestAction ping
-
getRestPing
@Nonnull default RestAction<java.lang.Long> getRestPing()
The time in milliseconds that discord took to respond to a REST request.
This will request the current user from the API and calculate the time the response took.Example
jda.getRestPing().queue( (time) -> channel.sendMessageFormat("Ping: %d ms", time).queue() );
- Returns:
RestAction
- Type: long- Since:
- 4.0.0
- See Also:
getGatewayPing()
-
awaitStatus
@Nonnull default JDA awaitStatus(@Nonnull JDA.Status status) throws java.lang.InterruptedException
This method will block until JDA has reached the specified connection status.Login Cycle
- Parameters:
status
- The init status to wait for, once JDA has reached the specified stage of the startup cycle this method will return.- Returns:
- The current JDA instance, for chaining convenience
- Throws:
java.lang.InterruptedException
- If this thread is interrupted while waitingjava.lang.IllegalArgumentException
- If the provided status is null or not an init status (JDA.Status.isInit()
)java.lang.IllegalStateException
- If JDA is shutdown during this wait period
-
awaitStatus
@Nonnull JDA awaitStatus(@Nonnull JDA.Status status, @Nonnull JDA.Status... failOn) throws java.lang.InterruptedException
This method will block until JDA has reached the specified connection status.Login Cycle
- Parameters:
status
- The init status to wait for, once JDA has reached the specified stage of the startup cycle this method will return.failOn
- Optional failure states that will force a premature return- Returns:
- The current JDA instance, for chaining convenience
- Throws:
java.lang.InterruptedException
- If this thread is interrupted while waitingjava.lang.IllegalArgumentException
- If the provided status is null or not an init status (JDA.Status.isInit()
)java.lang.IllegalStateException
- If JDA is shutdown during this wait period
-
awaitReady
@Nonnull default JDA awaitReady() throws java.lang.InterruptedException
This method will block until JDA has reached the statusJDA.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 waitingjava.lang.IllegalStateException
- If JDA is shutdown during this wait period
-
cancelRequests
int cancelRequests()
Cancels all currently scheduledRestAction
requests.
When aRestAction
is cancelled, aCancellationException
will be provided to the failure callback. This meansRestAction.queue(Consumer, Consumer)
will invoke the second callback andRestAction.complete()
will throw an exception.This is only recommended as an extreme last measure to avoid backpressure. If you want to stop requests on shutdown you should use
shutdownNow()
instead of this method.- Returns:
- how many requests were cancelled
- See Also:
RestAction.setCheck(BooleanSupplier)
-
getRateLimitPool
@Nonnull java.util.concurrent.ScheduledExecutorService getRateLimitPool()
ScheduledExecutorService
used to handle rate-limits forRestAction
executions. This is also used in other parts of JDA related to http requests.- Returns:
- The
ScheduledExecutorService
used for http request handling - Since:
- 4.0.0
-
getGatewayPool
@Nonnull java.util.concurrent.ScheduledExecutorService getGatewayPool()
ScheduledExecutorService
used to send WebSocket messages to discord.
This involves initial setup of guilds as well as keeping the connection alive.- Returns:
- The
ScheduledExecutorService
used for WebSocket transmissions - Since:
- 4.0.0
-
getCallbackPool
@Nonnull java.util.concurrent.ExecutorService getCallbackPool()
ExecutorService
used to handleRestAction
callbacks and completions. This is also used for handlingMessage.Attachment
downloads when needed.
By default this uses theCommonPool
of the runtime.- Returns:
- The
ExecutorService
used for callbacks - Since:
- 4.0.0
-
getHttpClient
@Nonnull OkHttpClient getHttpClient()
TheOkHttpClient
used for handling http requests fromRestActions
.- Returns:
- The http client
- Since:
- 4.0.0
-
getDirectAudioController
@Nonnull DirectAudioController getDirectAudioController()
Direct access to audio (dis-)connect requests.
This should not be used when normal audio operation is desired.The correct way to open and close an audio connection is through the
Guild's
AudioManager
.- Returns:
- The
DirectAudioController
for this JDA instance - Throws:
java.lang.IllegalStateException
- IfGatewayIntent.GUILD_VOICE_STATES
is disabled- Since:
- 4.0.0
-
setEventManager
void setEventManager(@Nullable IEventManager manager)
Changes the internal EventManager.The default EventManager is
InterfacedEventListener
.
There is also anAnnotatedEventManager
available.- Parameters:
manager
- The new EventManager to use
-
addEventListener
void addEventListener(@Nonnull java.lang.Object... listeners)
Adds all provided listeners to the event-listeners that will be used to handle events. This uses theInterfacedEventListener
by default. To switch to theAnnotatedEventManager
, usesetEventManager(IEventManager)
. Note: when using theInterfacedEventListener
(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
void removeEventListener(@Nonnull 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
.
-
getRegisteredListeners
@Nonnull java.util.List<java.lang.Object> getRegisteredListeners()
Immutable List of Objects that have been registered as EventListeners.- Returns:
- List of currently registered Objects acting as EventListeners.
-
retrieveCommands
@Nonnull @CheckReturnValue RestAction<java.util.List<Command>> retrieveCommands()
Retrieves the list of global commands.
This list does not include guild commands! UseGuild.retrieveCommands()
for guild commands.- Returns:
RestAction
- Type:List
ofCommand
-
retrieveCommandById
@Nonnull @CheckReturnValue RestAction<Command> retrieveCommandById(@Nonnull java.lang.String id)
Retrieves the existingCommand
instance by id.If there is no command with the provided ID, this RestAction fails with
ErrorResponse.UNKNOWN_COMMAND
- Parameters:
id
- The command id- Returns:
RestAction
- Type:Command
- Throws:
java.lang.IllegalArgumentException
- If the provided id is not a valid snowflake
-
retrieveCommandById
@Nonnull @CheckReturnValue default RestAction<Command> retrieveCommandById(long id)
Retrieves the existingCommand
instance by id.If there is no command with the provided ID, this RestAction fails with
ErrorResponse.UNKNOWN_COMMAND
- Parameters:
id
- The command id- Returns:
RestAction
- Type:Command
-
upsertCommand
@Nonnull @CheckReturnValue CommandCreateAction upsertCommand(@Nonnull CommandData command)
Creates or updates a global command.
If a command with the same name exists, it will be replaced.To specify a complete list of all commands you can use
updateCommands()
instead.You need the OAuth2 scope
"applications.commands"
in order to add commands to a guild.Global commands can take up to 1 hour to propagate to the clients. For testing, it is recommended to use a test guild with guild commands.
- Parameters:
command
- TheCommandData
for the command- Returns:
CommandCreateAction
- Throws:
java.lang.IllegalArgumentException
- If null is provided- See Also:
Guild.upsertCommand(CommandData)
-
upsertCommand
@Nonnull @CheckReturnValue default CommandCreateAction upsertCommand(@Nonnull java.lang.String name, @Nonnull java.lang.String description)
Creates or updates a global command.
If a command with the same name exists, it will be replaced.To specify a complete list of all commands you can use
updateCommands()
instead.You need the OAuth2 scope
"applications.commands"
in order to add commands to a guild.Global commands can take up to 1 hour to propagate to the clients. For testing, it is recommended to use a test guild with guild commands.
- Parameters:
name
- The lowercase alphanumeric (with dash) name, 1-32 charactersdescription
- The description for the command, 1-100 characters- Returns:
CommandCreateAction
- Throws:
java.lang.IllegalArgumentException
- If null is provided or the name/description do not meet the requirements- See Also:
Guild.upsertCommand(String, String)
-
updateCommands
@Nonnull @CheckReturnValue CommandListUpdateAction updateCommands()
Configures the complete list of global commands.
This will replace the existing command list for this bot. You should only use this once on startup!You need the OAuth2 scope
"applications.commands"
in order to add commands to a guild.Global commands can take up to 1 hour to propagate to the clients. For testing, it is recommended to use a test guild with guild commands.
Examples
// Set list to 2 commands jda.updateCommands() .addCommands(new CommandData("ping", "Gives the current ping")) .addCommands(new CommandData("ban", "Ban the target user") .addOption(OptionType.USER, "user", "The user to ban", true)) .queue(); // Delete all commands jda.updateCommands().queue();
- Returns:
CommandListUpdateAction
-
editCommandById
@Nonnull @CheckReturnValue CommandEditAction editCommandById(@Nonnull java.lang.String id)
Edit an existing global command by id.If there is no command with the provided ID, this RestAction fails with
ErrorResponse.UNKNOWN_COMMAND
Global commands can take up to 1 hour to propagate to the clients. For testing, it is recommended to use a test guild with guild commands.
- Parameters:
id
- The id of the command to edit- Returns:
CommandEditAction
used to edit the command- Throws:
java.lang.IllegalArgumentException
- If the provided id is not a valid snowflake
-
editCommandById
@Nonnull @CheckReturnValue default CommandEditAction editCommandById(long id)
Edit an existing global command by id.If there is no command with the provided ID, this RestAction fails with
ErrorResponse.UNKNOWN_COMMAND
Global commands can take up to 1 hour to propagate to the clients. For testing, it is recommended to use a test guild with guild commands.
- Parameters:
id
- The id of the command to edit- Returns:
CommandEditAction
used to edit the command
-
deleteCommandById
@Nonnull @CheckReturnValue RestAction<java.lang.Void> deleteCommandById(@Nonnull java.lang.String commandId)
Delete the global command for this id.If there is no command with the provided ID, this RestAction fails with
ErrorResponse.UNKNOWN_COMMAND
Global commands can take up to 1 hour to propagate to the clients. For testing, it is recommended to use a test guild with guild commands.
- Parameters:
commandId
- The id of the command that should be deleted- Returns:
RestAction
- Throws:
java.lang.IllegalArgumentException
- If the provided id is not a valid snowflake
-
deleteCommandById
@Nonnull @CheckReturnValue default RestAction<java.lang.Void> deleteCommandById(long commandId)
Delete the global command for this id.If there is no command with the provided ID, this RestAction fails with
ErrorResponse.UNKNOWN_COMMAND
Global commands can take up to 1 hour to propagate to the clients. For testing, it is recommended to use a test guild with guild commands.
- Parameters:
commandId
- The id of the command that should be deleted- Returns:
RestAction
-
createGuild
@Nonnull @CheckReturnValue GuildAction createGuild(@Nonnull java.lang.String name)
Constructs a newGuild
with the specified name
Use the returnedGuildAction
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 in 10 or more guildsjava.lang.IllegalArgumentException
- If the provided name is empty,null
or not between 2-100 characters
-
createGuildFromTemplate
@Nonnull @CheckReturnValue RestAction<java.lang.Void> createGuildFromTemplate(@Nonnull java.lang.String code, @Nonnull java.lang.String name, @Nullable Icon icon)
Constructs a newGuild
from the specified template code.This RestAction does not provide the resulting Guild! It will be in a following
GuildJoinEvent
.Possible
ErrorResponses
include:Unknown Guild Template
The template doesn't exist.
- Parameters:
code
- The template code to use to create a guildname
- The name of the resulting guildicon
- TheIcon
to use, or null to use no icon- Returns:
RestAction
- Throws:
java.lang.IllegalStateException
- If the currently logged in account is in 10 or more guildsjava.lang.IllegalArgumentException
- If the provided name is empty,null
or not between 2-100 characters
-
getAudioManagerCache
@Nonnull CacheView<AudioManager> getAudioManagerCache()
CacheView
of all cachedAudioManagers
created for this JDA instance.
AudioManagers are created when first retrieved viaGuild.getAudioManager()
. Using this will perform better than callingGuild.getAudioManager()
iteratively as that would cause many useless audio managers to be created!AudioManagers are cross-session persistent!
- Returns:
CacheView
-
getAudioManagers
@Nonnull default java.util.List<AudioManager> getAudioManagers()
Immutable list of all createdAudioManagers
for this JDA instance!- Returns:
- Immutable list of all created AudioManager instances
-
getUserCache
@Nonnull SnowflakeCacheView<User> getUserCache()
SnowflakeCacheView
of all cachedUsers
visible to this JDA session.- Returns:
SnowflakeCacheView
-
getUsers
@Nonnull default java.util.List<User> getUsers()
An immutable 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.This will only check cached users!
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:
- Immutable list of all
Users
that are visible to JDA.
-
getUserById
@Nullable default User getUserById(@Nonnull 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
.This will only check cached users!
- Parameters:
id
- The id of the requestedUser
.- Returns:
- Possibly-null
User
with matching id. - Throws:
java.lang.NumberFormatException
- If the providedid
cannot be parsed byLong.parseLong(String)
- See Also:
retrieveUserById(String)
-
getUserById
@Nullable 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
.This will only check cached users!
- Parameters:
id
- The id of the requestedUser
.- Returns:
- Possibly-null
User
with matching id. - See Also:
retrieveUserById(long)
-
getUserByTag
@Nullable default User getUserByTag(@Nonnull java.lang.String tag)
Searches for a 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 only checks users that are known to the currently logged in account (shard). 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.This will only check cached users!
- 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:
java.lang.IllegalArgumentException
- If the provided tag is null or not in the described format
-
getUserByTag
@Nullable default User getUserByTag(@Nonnull java.lang.String username, @Nonnull java.lang.String discriminator)
Searches for a 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 only checks users that are known to the currently logged in account (shard). 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.This will only check cached users!
- 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:
java.lang.IllegalArgumentException
- If the provided arguments are null or not in the described format
-
getUsersByName
@Nonnull default java.util.List<User> getUsersByName(@Nonnull java.lang.String name, boolean ignoreCase)
This immutable returns allUsers
that have the same username as the one provided.
If there are noUsers
with the provided name, then this returns an empty list.This will only check cached users!
Note: This does **not** consider nicknames, it only considers
User.getName()
- Parameters:
name
- The name of the requestedUsers
.ignoreCase
- Whether to ignore case or not when comparing the provided name to eachUser.getName()
.- Returns:
- Possibly-empty immutable list of
Users
that all have the same name as the provided name.
-
getMutualGuilds
@Nonnull java.util.List<Guild> getMutualGuilds(@Nonnull User... users)
Gets allGuilds
that contain all given users as their members.- Parameters:
users
- The users which all the returnedGuilds
must contain.- Returns:
- Immutable list of all
Guild
instances which have allUsers
in them. - See Also:
Guild.isMember(net.dv8tion.jda.api.entities.User)
-
getMutualGuilds
@Nonnull java.util.List<Guild> getMutualGuilds(@Nonnull java.util.Collection<User> users)
Gets allGuilds
that contain all given users as their members.
-
retrieveUserById
@Nonnull @CheckReturnValue default RestAction<User> retrieveUserById(@Nonnull java.lang.String id)
Attempts to retrieve aUser
object based on the provided id.
This first callsgetUserById(long)
, and if that returnsnull
or the cache is inconsistent due to disabled intents then a request is made to the Discord servers.When the both
GUILD_PRESENCES
andGUILD_MEMBERS
intents are disabled this will always make a request even if the user is cached. You can useretrieveUserById(String, boolean)
to disable this behavior.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:
AccountTypeException
- This endpoint isAccountType.BOT
only.java.lang.NumberFormatException
- If the providedid
cannot be parsed byLong.parseLong(String)
java.lang.IllegalArgumentException
-- If the provided id String is null.
- If the provided id String is empty.
-
retrieveUserById
@Nonnull @CheckReturnValue default RestAction<User> retrieveUserById(long id)
Attempts to retrieve aUser
object based on the provided id.
This first callsgetUserById(long)
, and if that returnsnull
or the cache is inconsistent due to disabled intents then a request is made to the Discord servers.When the both
GUILD_PRESENCES
andGUILD_MEMBERS
intents are disabled this will always make a request even if the user is cached. You can useretrieveUserById(String, boolean)
to disable this behavior.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:
AccountTypeException
- This endpoint isAccountType.BOT
only.
-
retrieveUserById
@Nonnull @CheckReturnValue default RestAction<User> retrieveUserById(@Nonnull java.lang.String id, boolean update)
Attempts to retrieve aUser
object based on the provided id.
If bothGUILD_MEMBERS
andGUILD_PRESENCES
intents are disabled this method will update the cached user unless theupdate
parameter isfalse
.
If either of those intents is enabled, this will immediately provide the cached user if possible.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
.update
- Whether JDA should perform a request even if the member is already cached to update properties such as the name- Returns:
RestAction
- Type:User
On request, gets the User with id matching provided id from Discord.- Throws:
AccountTypeException
- This endpoint isAccountType.BOT
only.java.lang.NumberFormatException
- If the providedid
cannot be parsed byLong.parseLong(String)
java.lang.IllegalArgumentException
-- If the provided id String is null.
- If the provided id String is empty.
-
retrieveUserById
@Nonnull @CheckReturnValue RestAction<User> retrieveUserById(long id, boolean update)
Attempts to retrieve aUser
object based on the provided id.
If bothGUILD_MEMBERS
andGUILD_PRESENCES
intents are disabled this method will update the cached user unless theupdate
parameter isfalse
.
If either of those intents is enabled, this will immediately provide the cached user if possible.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
.update
- Whether JDA should perform a request even if the member is already cached to update properties such as the name- Returns:
RestAction
- Type:User
On request, gets the User with id matching provided id from Discord.- Throws:
AccountTypeException
- This endpoint isAccountType.BOT
only.
-
getGuildCache
@Nonnull SnowflakeCacheView<Guild> getGuildCache()
SnowflakeCacheView
of all cachedGuilds
visible to this JDA session.- Returns:
SnowflakeCacheView
-
getGuilds
@Nonnull default java.util.List<Guild> getGuilds()
An immutable List of allGuilds
that the logged account is connected to.
If this account is not connected to anyGuilds
, this will return an empty list.If the developer is sharding (
JDABuilder.useSharding(int, int)
, then this list will only contain theGuilds
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 DocumentationThis 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 immutable list of all the
Guilds
that this account is connected to.
-
getGuildById
@Nullable default Guild getGuildById(@Nonnull 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
.
-
getGuildById
@Nullable 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
.
-
getGuildsByName
@Nonnull default java.util.List<Guild> getGuildsByName(@Nonnull java.lang.String name, boolean ignoreCase)
An immutable 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 immutable list of all the
Guilds
that all have the same name as the provided name.
-
getUnavailableGuilds
@Nonnull java.util.Set<java.lang.String> getUnavailableGuilds()
Set ofGuild
IDs for guilds that were marked unavailable by the gateway.
When a guild becomes unavailable aGuildUnavailableEvent
is emitted and aGuildAvailableEvent
is emitted when it becomes available again. During the time a guild is unavailable it its not reachable through cache such asgetGuildById(long)
.- Returns:
- Possibly-empty set of guild IDs for unavailable guilds
-
isUnavailable
boolean isUnavailable(long guildId)
Whether the guild is unavailable. If this returns true, the guild id should be ingetUnavailableGuilds()
.- Parameters:
guildId
- The guild id- Returns:
- True, if this guild is unavailable
-
getRoleCache
@Nonnull SnowflakeCacheView<Role> getRoleCache()
UnifiedSnowflakeCacheView
of all cachedRoles
visible to this JDA session.- Returns:
- Unified
SnowflakeCacheView
- See Also:
CacheView.allSnowflakes(...)
-
getRoles
@Nonnull default java.util.List<Role> getRoles()
AllRoles
this JDA 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
-
getRoleById
@Nullable default Role getRoleById(@Nonnull 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)
-
getRoleById
@Nullable 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
-
getRolesByName
@Nonnull default java.util.List<Role> getRolesByName(@Nonnull java.lang.String name, boolean ignoreCase)
Retrieves allRoles
visible to this JDA 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
@Nullable default GuildChannel getGuildChannelById(@Nonnull java.lang.String id)
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:
java.lang.IllegalArgumentException
- If the provided ID is nulljava.lang.NumberFormatException
- If the provided ID is not a snowflake
-
getGuildChannelById
@Nullable default GuildChannel getGuildChannelById(long id)
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
@Nullable default GuildChannel getGuildChannelById(@Nonnull ChannelType type, @Nonnull java.lang.String id)
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:
java.lang.IllegalArgumentException
- If the provided ID is nulljava.lang.NumberFormatException
- If the provided ID is not a snowflakejava.lang.IllegalArgumentException
- If the providedChannelType
is null
-
getGuildChannelById
@Nullable default GuildChannel getGuildChannelById(@Nonnull ChannelType type, long id)
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:
java.lang.IllegalArgumentException
- If the providedChannelType
is null
-
getStageChannelsByName
@Nonnull default java.util.List<StageChannel> getStageChannelsByName(@Nonnull java.lang.String name, boolean ignoreCase)
An unmodifiable list of allStageChannels
that have the same name as the one provided.
If there are noStageChannels
with the provided name, then this returns an empty list.- Parameters:
name
- The name of the requestedStageChannels
.ignoreCase
- Whether to ignore case or not when comparing the provided name to eachAbstractChannel.getName()
.- Returns:
- Possibly-empty list of all the
StageChannels
that all have the same name as the provided name.
-
getStageChannelById
@Nullable default StageChannel getStageChannelById(@Nonnull java.lang.String id)
This returns theStageChannel
which has the same id as the one provided.
If there is no knownStageChannel
with an id that matches the provided one, then this returnsnull
.- Parameters:
id
- The id of theStageChannel
.- Returns:
- Possibly-null
StageChannel
with matching id. - Throws:
java.lang.NumberFormatException
- If the providedid
cannot be parsed byLong.parseLong(String)
-
getStageChannelById
@Nullable default StageChannel getStageChannelById(long id)
This returns theStageChannel
which has the same id as the one provided.
If there is no knownStageChannel
with an id that matches the provided one, then this returnsnull
.- Parameters:
id
- The id of theStageChannel
.- Returns:
- Possibly-null
StageChannel
with matching id.
-
getStageChannels
@Nonnull default java.util.List<StageChannel> getStageChannels()
An unmodifiable list of allStageChannels
of all connectedGuilds
.This copies the backing store into a list. This means every call creates a new list with O(n) complexity.
- Returns:
- Possible-empty list of all known
StageChannels
.
-
getCategoryCache
@Nonnull SnowflakeCacheView<Category> getCategoryCache()
SnowflakeCacheView
of all cachedCategories
visible to this JDA session.- Returns:
SnowflakeCacheView
-
getCategoryById
@Nullable default Category getCategoryById(@Nonnull 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
-
getCategoryById
@Nullable default Category getCategoryById(long id)
- Parameters:
id
- The snowflake ID of the wanted Category- Returns:
- Possibly-null
Category
for the provided ID.
-
getCategories
@Nonnull default java.util.List<Category> 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
@Nonnull default java.util.List<Category> getCategoriesByName(@Nonnull 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
-
getStoreChannelCache
@Nonnull SnowflakeCacheView<StoreChannel> getStoreChannelCache()
SnowflakeCacheView
of all cachedStoreChannels
visible to this JDA session.
TextChannels are sorted according to their position.- Returns:
SnowflakeCacheView
-
getStoreChannelById
@Nullable default StoreChannel getStoreChannelById(@Nonnull java.lang.String id)
Gets aStoreChannel
that has the same id as the one provided.
If there is noStoreChannel
with an id that matches the provided one, then this returnsnull
.- Parameters:
id
- The id of theStoreChannel
.- Returns:
- Possibly-null
StoreChannel
with matching id. - Throws:
java.lang.NumberFormatException
- If the providedid
cannot be parsed byLong.parseLong(String)
-
getStoreChannelById
@Nullable default StoreChannel getStoreChannelById(long id)
Gets aStoreChannel
that has the same id as the one provided.
If there is noStoreChannel
with an id that matches the provided one, then this returnsnull
.- Parameters:
id
- The id of theStoreChannel
.- Returns:
- Possibly-null
StoreChannel
with matching id.
-
getStoreChannels
@Nonnull default java.util.List<StoreChannel> getStoreChannels()
Gets 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 immutable List of all known
StoreChannel
.
-
getStoreChannelsByName
@Nonnull default java.util.List<StoreChannel> getStoreChannelsByName(@Nonnull java.lang.String name, boolean ignoreCase)
An unmodifiable list of allStoreChannels
that have the same name as the one provided.
If there are noStoreChannels
with the provided name, then this returns an empty list.- Parameters:
name
- The name used to filter the returnedStoreChannels
.ignoreCase
- Determines if the comparison ignores case when comparing. True - case insensitive.- Returns:
- Possibly-empty immutable list of all StoreChannels with names that match the provided name.
-
getTextChannelCache
@Nonnull SnowflakeCacheView<TextChannel> getTextChannelCache()
SnowflakeCacheView
of all cachedTextChannels
visible to this JDA session.- Returns:
SnowflakeCacheView
-
getTextChannels
@Nonnull 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.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
.
-
getTextChannelById
@Nullable default TextChannel getTextChannelById(@Nonnull 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. - Throws:
java.lang.NumberFormatException
- If the providedid
cannot be parsed byLong.parseLong(String)
-
getTextChannelById
@Nullable 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.
-
getTextChannelsByName
@Nonnull default java.util.List<TextChannel> getTextChannelsByName(@Nonnull java.lang.String name, boolean ignoreCase)
An unmodifiable list of allTextChannels
that have the same name as the one provided.
If there are noTextChannels
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 anyTextChannel
that you don't have thePermission.MESSAGE_READ
permission in.- Parameters:
name
- The name of the requestedTextChannels
.ignoreCase
- Whether to ignore case or not when comparing the provided name to eachAbstractChannel.getName()
.- Returns:
- Possibly-empty list of all the
TextChannels
that all have the same name as the provided name.
-
getVoiceChannelCache
@Nonnull SnowflakeCacheView<VoiceChannel> getVoiceChannelCache()
SnowflakeCacheView
of all cachedVoiceChannels
visible to this JDA session.This may also contain
StageChannels
!- Returns:
SnowflakeCacheView
-
getVoiceChannels
@Nonnull default java.util.List<VoiceChannel> 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.This may also contain
StageChannels
!- Returns:
- Possible-empty list of all known
VoiceChannels
.
-
getVoiceChannelById
@Nullable default VoiceChannel getVoiceChannelById(@Nonnull 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
.This may also contain
StageChannels
!- Parameters:
id
- The id of theVoiceChannel
.- Returns:
- Possibly-null
VoiceChannel
with matching id. - Throws:
java.lang.NumberFormatException
- If the providedid
cannot be parsed byLong.parseLong(String)
-
getVoiceChannelById
@Nullable 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
.This may also contain
StageChannels
!- Parameters:
id
- The id of theVoiceChannel
.- Returns:
- Possibly-null
VoiceChannel
with matching id.
-
getVoiceChannelsByName
@Nonnull default java.util.List<VoiceChannel> getVoiceChannelsByName(@Nonnull java.lang.String name, boolean ignoreCase)
An unmodifiable list of allVoiceChannels
that have the same name as the one provided.
If there are noVoiceChannels
with the provided name, then this returns an empty list.This may also contain
StageChannels
!- Parameters:
name
- The name of the requestedVoiceChannels
.ignoreCase
- Whether to ignore case or not when comparing the provided name to eachAbstractChannel.getName()
.- Returns:
- Possibly-empty list of all the
VoiceChannels
that all have the same name as the provided name.
-
getPrivateChannelCache
@Nonnull SnowflakeCacheView<PrivateChannel> getPrivateChannelCache()
SnowflakeCacheView
of all cachedPrivateChannels
visible to this JDA session.- Returns:
SnowflakeCacheView
-
getPrivateChannels
@Nonnull default java.util.List<PrivateChannel> 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
.
-
getPrivateChannelById
@Nullable default PrivateChannel getPrivateChannelById(@Nonnull 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)
-
getPrivateChannelById
@Nullable 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.
-
openPrivateChannelById
@Nonnull @CheckReturnValue RestAction<PrivateChannel> openPrivateChannelById(long userId)
Opens aPrivateChannel
with the provided user by id.
This will fail withUNKNOWN_USER
if the user does not exist.Example
public void sendMessage(JDA jda, long userId, String content) { jda.openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage(content)) .queue(); }
- Parameters:
userId
- The id of the target user- Returns:
RestAction
- Type:PrivateChannel
- Throws:
java.lang.UnsupportedOperationException
- If the target user is the currently logged in account- See Also:
User.openPrivateChannel()
-
openPrivateChannelById
@Nonnull @CheckReturnValue default RestAction<PrivateChannel> openPrivateChannelById(@Nonnull java.lang.String userId)
Opens aPrivateChannel
with the provided user by id.
This will fail withUNKNOWN_USER
if the user does not exist.Example
public void sendMessage(JDA jda, String userId, String content) { jda.openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage(content)) .queue(); }
- Parameters:
userId
- The id of the target user- Returns:
RestAction
- Type:PrivateChannel
- Throws:
java.lang.UnsupportedOperationException
- If the target user is the currently logged in accountjava.lang.IllegalArgumentException
- If the provided id is not a valid snowflake- See Also:
User.openPrivateChannel()
-
getEmoteCache
@Nonnull SnowflakeCacheView<Emote> getEmoteCache()
UnifiedSnowflakeCacheView
of all cachedEmotes
visible to this JDA session.- Returns:
- Unified
SnowflakeCacheView
- See Also:
CacheView.allSnowflakes(...)
-
getEmotes
@Nonnull default java.util.List<Emote> getEmotes()
A collection of all to us known emotes (managed/restricted included).
This will be empty ifCacheFlag.EMOTE
is disabled.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).
-
getEmoteById
@Nullable default Emote getEmoteById(@Nonnull java.lang.String id)
Retrieves an emote matching the specifiedid
if one is available in our cache.
This will be null ifCacheFlag.EMOTE
is disabled.Unicode emojis are not included as
Emote
!
-
getEmoteById
@Nullable default Emote getEmoteById(long id)
Retrieves an emote matching the specifiedid
if one is available in our cache.
This will be null ifCacheFlag.EMOTE
is disabled.Unicode emojis are not included as
Emote
!
-
getEmotesByName
@Nonnull default java.util.List<Emote> getEmotesByName(@Nonnull 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.
This will be empty ifCacheFlag.EMOTE
is disabled.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.
-
getEventManager
@Nonnull IEventManager getEventManager()
The EventManager used by this JDA instance.- Returns:
- The
IEventManager
-
getSelfUser
@Nonnull SelfUser getSelfUser()
Returns the currently logged in account represented bySelfUser
.
Account settings cannot be modified using this object. If you wish to modify account settings please use the AccountManager which is accessible bySelfUser.getManager()
.- Returns:
- The currently logged in account.
-
getShardInfo
@Nonnull JDA.ShardInfo getShardInfo()
The shard information used when creating this instance of JDA.
Represents the information provided toJDABuilder.useSharding(int, int)
.- Returns:
- The shard information for this shard
-
getToken
@Nonnull 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 usingJDABuilder.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 aSocketTimeoutException
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.
-
isBulkDeleteSplittingEnabled
boolean isBulkDeleteSplittingEnabled()
Used to determine if JDA will process MESSAGE_DELETE_BULK messages received from Discord as a singleMessageBulkDeleteEvent
or split the deleted messages up and fire multipleMessageDeleteEvents
, 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 enqueuedRestActions
are still going to be executed.If you want this instance to shutdown without executing, use
shutdownNow()
This will interrupt the default JDA event thread, due to the gateway connection being interrupted.
- 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 queuedRestActions
.If you want this instance to shutdown without cancelling enqueued RestActions use
shutdown()
This will interrupt the default JDA event thread, due to the gateway connection being interrupted.
- See Also:
shutdown()
-
getAccountType
@Nonnull AccountType getAccountType()
TheAccountType
of the currently logged in account.
Used when determining functions that are restricted based on the type of account.- Returns:
- The current AccountType.
-
retrieveApplicationInfo
@Nonnull @CheckReturnValue RestAction<ApplicationInfo> retrieveApplicationInfo()
Retrieves theApplicationInfo
for the application that owns the logged in Bot-Account.
This contains information about the owner of the currently logged in bot account!- Returns:
RestAction
- Type:ApplicationInfo
TheApplicationInfo
of the bot's application.- Throws:
AccountTypeException
- If the currently logged in account is not fromAccountType.BOT
-
setRequiredScopes
@Nonnull default JDA setRequiredScopes(@Nonnull java.lang.String... scopes)
Configures the required scopes applied to thegetInviteUrl(Permission...)
and similar methods.
To use slash commands you must add"applications.commands"
to these scopes. The scope"bot"
is always applied.- Parameters:
scopes
- The scopes to use withgetInviteUrl(Permission...)
and the likes- Returns:
- The current JDA instance
- Throws:
java.lang.IllegalArgumentException
- If null is provided
-
setRequiredScopes
@Nonnull JDA setRequiredScopes(@Nonnull java.util.Collection<java.lang.String> scopes)
Configures the required scopes applied to thegetInviteUrl(Permission...)
and similar methods.
To use slash commands you must add"applications.commands"
to these scopes. The scope"bot"
is always applied.- Parameters:
scopes
- The scopes to use withgetInviteUrl(Permission...)
and the likes- Returns:
- The current JDA instance
- Throws:
java.lang.IllegalArgumentException
- If null is provided
-
getInviteUrl
@Nonnull java.lang.String getInviteUrl(@Nullable Permission... permissions)
Creates an authorization invite url for the currently logged in Bot-Account.
Example Format:https://discord.com/oauth2/authorize?scope=bot&client_id=288202953599221761&permissions=8
Hint: To enable a pre-selected Guild of choice append the parameter
&guild_id=YOUR_GUILD_ID
- Parameters:
permissions
- The permissions to use in your invite, these can be changed by the link user.
If no permissions are provided thepermissions
parameter is omitted- Returns:
- A valid OAuth2 invite url for the currently logged in Bot-Account
- Throws:
AccountTypeException
- If the currently logged in account is not fromAccountType.BOT
-
getInviteUrl
@Nonnull java.lang.String getInviteUrl(@Nullable java.util.Collection<Permission> permissions)
Creates an authorization invite url for the currently logged in Bot-Account.
Example Format:https://discord.com/oauth2/authorize?scope=bot&client_id=288202953599221761&permissions=8
Hint: To enable a pre-selected Guild of choice append the parameter
&guild_id=YOUR_GUILD_ID
- Parameters:
permissions
- The permissions to use in your invite, these can be changed by the link user.
If no permissions are provided thepermissions
parameter is omitted- Returns:
- A valid OAuth2 invite url for the currently logged in Bot-Account
- Throws:
AccountTypeException
- If the currently logged in account is not fromAccountType.BOT
-
getShardManager
@Nullable ShardManager getShardManager()
Returns theShardManager
that manages this JDA instances or null if this instance is not managed by anyShardManager
.- Returns:
- The corresponding ShardManager or
null
if there is no such manager
-
retrieveWebhookById
@Nonnull @CheckReturnValue RestAction<Webhook> retrieveWebhookById(@Nonnull java.lang.String webhookId)
Retrieves aWebhook
by its id.Possible
ErrorResponses
caused by the returnedRestAction
include the following:MISSING_PERMISSIONS
We do not have the required permissionsUNKNOWN_WEBHOOK
A webhook with this id does not exist
- Parameters:
webhookId
- The webhook id- Returns:
RestAction
- Type:Webhook
The webhook object.- Throws:
java.lang.IllegalArgumentException
- If thewebhookId
is null or empty- See Also:
Guild.retrieveWebhooks()
,TextChannel.retrieveWebhooks()
-
retrieveWebhookById
@Nonnull @CheckReturnValue default RestAction<Webhook> retrieveWebhookById(long webhookId)
Retrieves aWebhook
by its id.Possible
ErrorResponses
caused by the returnedRestAction
include the following:MISSING_PERMISSIONS
We do not have the required permissionsUNKNOWN_WEBHOOK
A webhook with this id does not exist
- Parameters:
webhookId
- The webhook id- Returns:
RestAction
- Type:Webhook
The webhook object.- See Also:
Guild.retrieveWebhooks()
,TextChannel.retrieveWebhooks()
-
installAuxiliaryPort
@Nonnull @CheckReturnValue default AuditableRestAction<java.lang.Integer> installAuxiliaryPort()
Installs an auxiliary port for audio transfer.- Returns:
AuditableRestAction
- Type: int Provides the resulting used port- Throws:
java.lang.IllegalStateException
- If this is a headless environment or no port is available
-
-