Class DiscordApiBuilder
- java.lang.Object
-
- org.javacord.api.DiscordApiBuilder
-
- All Implemented Interfaces:
ChainableGloballyAttachableListenerManager
public class DiscordApiBuilder extends java.lang.Object implements ChainableGloballyAttachableListenerManager
This class is used to login to a Discord account.
-
-
Constructor Summary
Constructors Constructor Description DiscordApiBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DiscordApiBuilder
addIntents(Intent... intents)
Adds the given intents to the already set.<T extends GloballyAttachableListener>
DiscordApiBuilderaddListener(java.lang.Class<T> listenerClass, java.util.function.Function<DiscordApi,T> listenerFunction)
Adds aGloballyAttachableListener
to all createdDiscordApi
instances.<T extends GloballyAttachableListener>
DiscordApiBuilderaddListener(java.lang.Class<T> listenerClass, java.util.function.Supplier<T> listenerSupplier)
Adds aGloballyAttachableListener
to all createdDiscordApi
instances.<T extends GloballyAttachableListener>
DiscordApiBuilderaddListener(java.lang.Class<T> listenerClass, T listener)
Adds aGloballyAttachableListener
to all createdDiscordApi
instances.DiscordApiBuilder
addListener(java.util.function.Function<DiscordApi,GloballyAttachableListener> listenerFunction)
Adds a listener that implements one or moreGloballyAttachableListener
s to all createdDiscordApi
instances.DiscordApiBuilder
addListener(java.util.function.Supplier<GloballyAttachableListener> listenerSupplier)
Adds a listener that implements one or moreGloballyAttachableListener
s to all createdDiscordApi
instances.DiscordApiBuilder
addListener(GloballyAttachableListener listener)
Adds a listener that implements one or moreGloballyAttachableListener
s to all createdDiscordApi
instances.int
getCurrentShard()
Gets the current shard.java.util.Optional<java.lang.String>
getToken()
Gets the token that will be used to login.int
getTotalShards()
Gets the total amount of shards.boolean
isShutdownHookRegistrationEnabled()
Checks if newly createdDiscordApi
instances should register a shutdown hook to disconnect the instance.boolean
isUserCachedEnabled()
Gets whether the user cache is enabled.boolean
isWaitingForServersOnStartup()
Checks if Javacord should wait for all servers to become available on startup.boolean
isWaitingForUsersOnStartup()
Checks if Javacord should wait for all users to be cached.java.util.concurrent.CompletableFuture<DiscordApi>
login()
Login to the account with the given token.java.util.List<java.util.concurrent.CompletableFuture<DiscordApi>>
loginAllShards()
Login all shards to the account with the given token.java.util.List<java.util.concurrent.CompletableFuture<DiscordApi>>
loginShards(int... shards)
Login given shards to the account with the given token.java.util.List<java.util.concurrent.CompletableFuture<DiscordApi>>
loginShards(java.util.function.IntPredicate shardsCondition)
Login shards adhering to the given predicate to the account with the given token.<T extends GloballyAttachableListener>
DiscordApiBuilderremoveListener(java.lang.Class<T> listenerClass, T listener)
Removes aGloballyAttachableListener
from the list of listeners to be added toDiscordApi
instances.DiscordApiBuilder
removeListener(GloballyAttachableListener listener)
Removes a listener that implements one or moreGloballyAttachableListener
s from the list of listeners to be added toDiscordApi
instances.<T extends GloballyAttachableListener>
DiscordApiBuilderremoveListenerFunction(java.lang.Class<T> listenerClass, java.util.function.Function<DiscordApi,T> listenerFunction)
Removes a function that providesGloballyAttachableListener
s from the list of listeners to be added toDiscordApi
instances.DiscordApiBuilder
removeListenerFunction(java.util.function.Function<DiscordApi,GloballyAttachableListener> listenerFunction)
Removes a function that provides listeners that implements one or moreGloballyAttachableListener
s from the list of listeners to be added toDiscordApi
instances.<T extends GloballyAttachableListener>
DiscordApiBuilderremoveListenerSupplier(java.lang.Class<T> listenerClass, java.util.function.Supplier<T> listenerSupplier)
Removes a supplier ofGloballyAttachableListener
s from the list of listeners to be added toDiscordApi
instances.DiscordApiBuilder
removeListenerSupplier(java.util.function.Supplier<GloballyAttachableListener> listenerSupplier)
Removes a supplier of listeners that implements one or moreGloballyAttachableListener
s from the list of listeners to be added toDiscordApi
instances.DiscordApiBuilder
setAllIntents()
Sets all intents.DiscordApiBuilder
setAllIntentsExcept(Intent... intentsToOmit)
Sets all intents except the given intents.DiscordApiBuilder
setAllIntentsWhere(java.util.function.Predicate<Intent> condition)
Sets the intents where the given predicate matches.DiscordApiBuilder
setAllNonPrivilegedIntents()
Sets all non-privileged intents.DiscordApiBuilder
setAllNonPrivilegedIntentsAnd(Intent... intentsToInclude)
Sets all non-privileged intents and the given intents.DiscordApiBuilder
setAllNonPrivilegedIntentsExcept(Intent... intentsToOmit)
Sets all non privileged intents except the given intents.DiscordApiBuilder
setCurrentShard(int currentShard)
Sets shard for server sharding.DiscordApiBuilder
setEventsDispatchable(boolean dispatchEvents)
Sets whether this API instance can dispatch events.DiscordApiBuilder
setGatewayIdentifyRatelimiter(Ratelimiter ratelimiter)
Sets a ratelimiter that can be used to control the 5 seconds gateway identify ratelimit.DiscordApiBuilder
setGlobalRatelimiter(Ratelimiter ratelimiter)
Sets a ratelimiter that can be used to control global ratelimits.DiscordApiBuilder
setIntents(Intent... intents)
Sets intent for the events which should be received.DiscordApiBuilder
setProxy(java.net.Proxy proxy)
Sets the proxy which should be used to connect to the Discord REST API and web socket.DiscordApiBuilder
setProxyAuthenticator(Authenticator authenticator)
Sets the authenticator that should be used to authenticate against proxies that require it.DiscordApiBuilder
setProxySelector(java.net.ProxySelector proxySelector)
Sets the proxy selector which should be used to determine the proxies that should be used to connect to the Discord REST API and web socket.java.util.concurrent.CompletableFuture<DiscordApiBuilder>
setRecommendedTotalShards()
Retrieves the recommended shards count from the Discord API and sets it in this builder.DiscordApiBuilder
setShutdownHookRegistrationEnabled(boolean registerShutdownHook)
Sets if Javacord should register a shutdown hook that disconnects theDiscordApi
instance.DiscordApiBuilder
setToken(java.lang.String token)
Sets the token which is required for the login process.DiscordApiBuilder
setTotalShards(int totalShards)
Sets total shards for server sharding.DiscordApiBuilder
setTrustAllCertificates(boolean trustAllCertificates)
Sets whether all SSL certificates should be trusted when connecting to the Discord API and web socket.DiscordApiBuilder
setUserCacheEnabled(boolean enabled)
Sets whether the user cache should be enabled.DiscordApiBuilder
setWaitForServersOnStartup(boolean waitForServersOnStartup)
Sets if Javacord should wait for all servers to become available on startup.DiscordApiBuilder
setWaitForUsersOnStartup(boolean waitForUsersOnStartup)
Sets if Javacord should wait for all users to be cached.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.javacord.api.listener.ChainableGloballyAttachableListenerManager
addApplicationCommandPermissionsUpdateListener, addApplicationCommandPermissionsUpdateListener, addApplicationCommandPermissionsUpdateListener, addAudioSourceFinishedListener, addAudioSourceFinishedListener, addAudioSourceFinishedListener, addAutocompleteCreateListener, addAutocompleteCreateListener, addAutocompleteCreateListener, addButtonClickListener, addButtonClickListener, addButtonClickListener, addCachedMessagePinListener, addCachedMessagePinListener, addCachedMessagePinListener, addCachedMessageUnpinListener, addCachedMessageUnpinListener, addCachedMessageUnpinListener, addChannelPinsUpdateListener, addChannelPinsUpdateListener, addChannelPinsUpdateListener, addInteractionCreateListener, addInteractionCreateListener, addInteractionCreateListener, addKnownCustomEmojiChangeNameListener, addKnownCustomEmojiChangeNameListener, addKnownCustomEmojiChangeNameListener, addKnownCustomEmojiChangeWhitelistedRolesListener, addKnownCustomEmojiChangeWhitelistedRolesListener, addKnownCustomEmojiChangeWhitelistedRolesListener, addKnownCustomEmojiCreateListener, addKnownCustomEmojiCreateListener, addKnownCustomEmojiCreateListener, addKnownCustomEmojiDeleteListener, addKnownCustomEmojiDeleteListener, addKnownCustomEmojiDeleteListener, addLostConnectionListener, addLostConnectionListener, addLostConnectionListener, addMessageComponentCreateListener, addMessageComponentCreateListener, addMessageComponentCreateListener, addMessageContextMenuCommandListener, addMessageContextMenuCommandListener, addMessageContextMenuCommandListener, addMessageCreateListener, addMessageCreateListener, addMessageCreateListener, addMessageDeleteListener, addMessageDeleteListener, addMessageDeleteListener, addMessageEditListener, addMessageEditListener, addMessageEditListener, addMessageReplyListener, addMessageReplyListener, addMessageReplyListener, addModalSubmitListener, addModalSubmitListener, addModalSubmitListener, addPrivateChannelCreateListener, addPrivateChannelCreateListener, addPrivateChannelCreateListener, addPrivateChannelDeleteListener, addPrivateChannelDeleteListener, addPrivateChannelDeleteListener, addReactionAddListener, addReactionAddListener, addReactionAddListener, addReactionRemoveAllListener, addReactionRemoveAllListener, addReactionRemoveAllListener, addReactionRemoveListener, addReactionRemoveListener, addReactionRemoveListener, addReconnectListener, addReconnectListener, addReconnectListener, addResumeListener, addResumeListener, addResumeListener, addRoleChangeColorListener, addRoleChangeColorListener, addRoleChangeColorListener, addRoleChangeHoistListener, addRoleChangeHoistListener, addRoleChangeHoistListener, addRoleChangeMentionableListener, addRoleChangeMentionableListener, addRoleChangeMentionableListener, addRoleChangeNameListener, addRoleChangeNameListener, addRoleChangeNameListener, addRoleChangePermissionsListener, addRoleChangePermissionsListener, addRoleChangePermissionsListener, addRoleChangePositionListener, addRoleChangePositionListener, addRoleChangePositionListener, addRoleCreateListener, addRoleCreateListener, addRoleCreateListener, addRoleDeleteListener, addRoleDeleteListener, addRoleDeleteListener, addSelectMenuChooseListener, addSelectMenuChooseListener, addSelectMenuChooseListener, addServerBecomesAvailableListener, addServerBecomesAvailableListener, addServerBecomesAvailableListener, addServerBecomesUnavailableListener, addServerBecomesUnavailableListener, addServerBecomesUnavailableListener, addServerChangeAfkChannelListener, addServerChangeAfkChannelListener, addServerChangeAfkChannelListener, addServerChangeAfkTimeoutListener, addServerChangeAfkTimeoutListener, addServerChangeAfkTimeoutListener, addServerChangeBoostCountListener, addServerChangeBoostCountListener, addServerChangeBoostCountListener, addServerChangeBoostLevelListener, addServerChangeBoostLevelListener, addServerChangeBoostLevelListener, addServerChangeDefaultMessageNotificationLevelListener, addServerChangeDefaultMessageNotificationLevelListener, addServerChangeDefaultMessageNotificationLevelListener, addServerChangeDescriptionListener, addServerChangeDescriptionListener, addServerChangeDescriptionListener, addServerChangeDiscoverySplashListener, addServerChangeDiscoverySplashListener, addServerChangeDiscoverySplashListener, addServerChangeExplicitContentFilterLevelListener, addServerChangeExplicitContentFilterLevelListener, addServerChangeExplicitContentFilterLevelListener, addServerChangeIconListener, addServerChangeIconListener, addServerChangeIconListener, addServerChangeModeratorsOnlyChannelListener, addServerChangeModeratorsOnlyChannelListener, addServerChangeModeratorsOnlyChannelListener, addServerChangeMultiFactorAuthenticationLevelListener, addServerChangeMultiFactorAuthenticationLevelListener, addServerChangeMultiFactorAuthenticationLevelListener, addServerChangeNameListener, addServerChangeNameListener, addServerChangeNameListener, addServerChangeNsfwLevelListener, addServerChangeNsfwLevelListener, addServerChangeNsfwLevelListener, addServerChangeOwnerListener, addServerChangeOwnerListener, addServerChangeOwnerListener, addServerChangePreferredLocaleListener, addServerChangePreferredLocaleListener, addServerChangePreferredLocaleListener, addServerChangeRegionListener, addServerChangeRegionListener, addServerChangeRegionListener, addServerChangeRulesChannelListener, addServerChangeRulesChannelListener, addServerChangeRulesChannelListener, addServerChangeServerFeatureListener, addServerChangeServerFeatureListener, addServerChangeServerFeatureListener, addServerChangeSplashListener, addServerChangeSplashListener, addServerChangeSplashListener, addServerChangeSystemChannelListener, addServerChangeSystemChannelListener, addServerChangeSystemChannelListener, addServerChangeVanityUrlCodeListener, addServerChangeVanityUrlCodeListener, addServerChangeVanityUrlCodeListener, addServerChangeVerificationLevelListener, addServerChangeVerificationLevelListener, addServerChangeVerificationLevelListener, addServerChannelChangeNameListener, addServerChannelChangeNameListener, addServerChannelChangeNameListener, addServerChannelChangeNsfwFlagListener, addServerChannelChangeNsfwFlagListener, addServerChannelChangeNsfwFlagListener, addServerChannelChangeOverwrittenPermissionsListener, addServerChannelChangeOverwrittenPermissionsListener, addServerChannelChangeOverwrittenPermissionsListener, addServerChannelChangePositionListener, addServerChannelChangePositionListener, addServerChannelChangePositionListener, addServerChannelCreateListener, addServerChannelCreateListener, addServerChannelCreateListener, addServerChannelDeleteListener, addServerChannelDeleteListener, addServerChannelDeleteListener, addServerChannelInviteCreateListener, addServerChannelInviteCreateListener, addServerChannelInviteCreateListener, addServerChannelInviteDeleteListener, addServerChannelInviteDeleteListener, addServerChannelInviteDeleteListener, addServerJoinListener, addServerJoinListener, addServerJoinListener, addServerLeaveListener, addServerLeaveListener, addServerLeaveListener, addServerMemberBanListener, addServerMemberBanListener, addServerMemberBanListener, addServerMemberJoinListener, addServerMemberJoinListener, addServerMemberJoinListener, addServerMemberLeaveListener, addServerMemberLeaveListener, addServerMemberLeaveListener, addServerMembersChunkListener, addServerMembersChunkListener, addServerMembersChunkListener, addServerMemberUnbanListener, addServerMemberUnbanListener, addServerMemberUnbanListener, addServerPrivateThreadJoinListener, addServerPrivateThreadJoinListener, addServerPrivateThreadJoinListener, addServerStageVoiceChannelChangeTopicListener, addServerStageVoiceChannelChangeTopicListener, addServerStageVoiceChannelChangeTopicListener, addServerTextChannelChangeDefaultAutoArchiveDurationListener, addServerTextChannelChangeDefaultAutoArchiveDurationListener, addServerTextChannelChangeDefaultAutoArchiveDurationListener, addServerTextChannelChangeSlowmodeListener, addServerTextChannelChangeSlowmodeListener, addServerTextChannelChangeSlowmodeListener, addServerTextChannelChangeTopicListener, addServerTextChannelChangeTopicListener, addServerTextChannelChangeTopicListener, addServerThreadChannelChangeArchivedListener, addServerThreadChannelChangeArchivedListener, addServerThreadChannelChangeArchivedListener, addServerThreadChannelChangeArchiveTimestampListener, addServerThreadChannelChangeArchiveTimestampListener, addServerThreadChannelChangeArchiveTimestampListener, addServerThreadChannelChangeAutoArchiveDurationListener, addServerThreadChannelChangeAutoArchiveDurationListener, addServerThreadChannelChangeAutoArchiveDurationListener, addServerThreadChannelChangeInvitableListener, addServerThreadChannelChangeInvitableListener, addServerThreadChannelChangeInvitableListener, addServerThreadChannelChangeLastMessageIdListener, addServerThreadChannelChangeLastMessageIdListener, addServerThreadChannelChangeLastMessageIdListener, addServerThreadChannelChangeLockedListener, addServerThreadChannelChangeLockedListener, addServerThreadChannelChangeLockedListener, addServerThreadChannelChangeMemberCountListener, addServerThreadChannelChangeMemberCountListener, addServerThreadChannelChangeMemberCountListener, addServerThreadChannelChangeMessageCountListener, addServerThreadChannelChangeMessageCountListener, addServerThreadChannelChangeMessageCountListener, addServerThreadChannelChangeRateLimitPerUserListener, addServerThreadChannelChangeRateLimitPerUserListener, addServerThreadChannelChangeRateLimitPerUserListener, addServerThreadChannelChangeTotalMessageSentListener, addServerThreadChannelChangeTotalMessageSentListener, addServerThreadChannelChangeTotalMessageSentListener, addServerThreadChannelCreateListener, addServerThreadChannelCreateListener, addServerThreadChannelCreateListener, addServerThreadChannelDeleteListener, addServerThreadChannelDeleteListener, addServerThreadChannelDeleteListener, addServerThreadChannelMembersUpdateListener, addServerThreadChannelMembersUpdateListener, addServerThreadChannelMembersUpdateListener, addServerThreadChannelUpdateListener, addServerThreadChannelUpdateListener, addServerThreadChannelUpdateListener, addServerThreadListSyncListener, addServerThreadListSyncListener, addServerThreadListSyncListener, addServerVoiceChannelChangeBitrateListener, addServerVoiceChannelChangeBitrateListener, addServerVoiceChannelChangeBitrateListener, addServerVoiceChannelChangeNsfwListener, addServerVoiceChannelChangeNsfwListener, addServerVoiceChannelChangeNsfwListener, addServerVoiceChannelChangeUserLimitListener, addServerVoiceChannelChangeUserLimitListener, addServerVoiceChannelChangeUserLimitListener, addServerVoiceChannelMemberJoinListener, addServerVoiceChannelMemberJoinListener, addServerVoiceChannelMemberJoinListener, addServerVoiceChannelMemberLeaveListener, addServerVoiceChannelMemberLeaveListener, addServerVoiceChannelMemberLeaveListener, addSlashCommandCreateListener, addSlashCommandCreateListener, addSlashCommandCreateListener, addStickerChangeDescriptionListener, addStickerChangeDescriptionListener, addStickerChangeDescriptionListener, addStickerChangeNameListener, addStickerChangeNameListener, addStickerChangeNameListener, addStickerChangeTagsListener, addStickerChangeTagsListener, addStickerChangeTagsListener, addStickerCreateListener, addStickerCreateListener, addStickerCreateListener, addStickerDeleteListener, addStickerDeleteListener, addStickerDeleteListener, addUserChangeActivityListener, addUserChangeActivityListener, addUserChangeActivityListener, addUserChangeAvatarListener, addUserChangeAvatarListener, addUserChangeAvatarListener, addUserChangeDeafenedListener, addUserChangeDeafenedListener, addUserChangeDeafenedListener, addUserChangeDiscriminatorListener, addUserChangeDiscriminatorListener, addUserChangeDiscriminatorListener, addUserChangeMutedListener, addUserChangeMutedListener, addUserChangeMutedListener, addUserChangeNameListener, addUserChangeNameListener, addUserChangeNameListener, addUserChangeNicknameListener, addUserChangeNicknameListener, addUserChangeNicknameListener, addUserChangePendingListener, addUserChangePendingListener, addUserChangePendingListener, addUserChangeSelfDeafenedListener, addUserChangeSelfDeafenedListener, addUserChangeSelfDeafenedListener, addUserChangeSelfMutedListener, addUserChangeSelfMutedListener, addUserChangeSelfMutedListener, addUserChangeServerAvatarListener, addUserChangeServerAvatarListener, addUserChangeServerAvatarListener, addUserChangeStatusListener, addUserChangeStatusListener, addUserChangeStatusListener, addUserChangeTimeoutListener, addUserChangeTimeoutListener, addUserChangeTimeoutListener, addUserContextMenuCommandListener, addUserContextMenuCommandListener, addUserContextMenuCommandListener, addUserRoleAddListener, addUserRoleAddListener, addUserRoleAddListener, addUserRoleRemoveListener, addUserRoleRemoveListener, addUserRoleRemoveListener, addUserStartTypingListener, addUserStartTypingListener, addUserStartTypingListener, addVoiceServerUpdateListener, addVoiceServerUpdateListener, addVoiceServerUpdateListener, addVoiceStateUpdateListener, addVoiceStateUpdateListener, addVoiceStateUpdateListener, addWebhooksUpdateListener, addWebhooksUpdateListener, addWebhooksUpdateListener
-
-
-
-
Method Detail
-
login
public java.util.concurrent.CompletableFuture<DiscordApi> login()
Login to the account with the given token.- Returns:
- A
CompletableFuture
which contains the DiscordApi.
-
loginAllShards
public java.util.List<java.util.concurrent.CompletableFuture<DiscordApi>> loginAllShards()
Login all shards to the account with the given token. It is invalid to callsetCurrentShard(int)
with anything but0
before calling this method.- Returns:
- A list of
CompletableFuture
s which contain theDiscordApi
s for the shards.
-
loginShards
public java.util.List<java.util.concurrent.CompletableFuture<DiscordApi>> loginShards(java.util.function.IntPredicate shardsCondition)
Login shards adhering to the given predicate to the account with the given token. It is invalid to callsetCurrentShard(int)
with anything but0
before calling this method.- Parameters:
shardsCondition
- The predicate for identifying shards to connect, starting with0
!- Returns:
- A list of
CompletableFuture
s which contain theDiscordApi
s for the shards.
-
loginShards
public java.util.List<java.util.concurrent.CompletableFuture<DiscordApi>> loginShards(int... shards)
Login given shards to the account with the given token. It is invalid to callsetCurrentShard(int)
with anything but0
before calling this method.- Parameters:
shards
- The shards to connect, starting with0
!- Returns:
- A list of
CompletableFuture
s which contain theDiscordApi
s for the shards.
-
setGlobalRatelimiter
public DiscordApiBuilder setGlobalRatelimiter(Ratelimiter ratelimiter)
Sets a ratelimiter that can be used to control global ratelimits.If you don't provide a ratelimiter by yourself, Javacord will use a default ratelimiter which is set to
5
requests per112 ms
, resulting in about 45 requests per second. The default ratelimiter will be shared by every bot with the same token in the same Java program.If you provide a custom ratelimiter, you have to make sure to use the exact same ratelimiter instance with all Javacord instances, or otherwise synchronize the global ratelimit across shards.
An easy implementation is available with the
LocalRatelimiter
.- Parameters:
ratelimiter
- The ratelimiter used to control global ratelimits.- Returns:
- The current instance in order to chain call methods.
-
setGatewayIdentifyRatelimiter
public DiscordApiBuilder setGatewayIdentifyRatelimiter(Ratelimiter ratelimiter)
Sets a ratelimiter that can be used to control the 5 seconds gateway identify ratelimit.By default, Javacord automatically provides a default
LocalRatelimiter
which is set to allow one gateway identify request per 5500ms and is shared with every bot with the same token in the same Java program.**DO NOT** set a custom gateway identify ratelimiter unless you have to synchronize the ratelimit across multiple Java programs (running on different JVMs, VMs, physical servers etc.) that run Javacord on the same bot token. The default ratelimiter will handle the ratelimit for you as long as your whole bot runs in the same Java program.
- Parameters:
ratelimiter
- The ratelimiter used to control the 5 seconds gateway identify ratelimit.- Returns:
- The current instance in order to chain call methods.
-
setEventsDispatchable
public DiscordApiBuilder setEventsDispatchable(boolean dispatchEvents)
Sets whether this API instance can dispatch events.- Parameters:
dispatchEvents
- Whether events can be dispatched.- Returns:
- The current instance in order to chain call methods.
-
setProxySelector
public DiscordApiBuilder setProxySelector(java.net.ProxySelector proxySelector)
Sets the proxy selector which should be used to determine the proxies that should be used to connect to the Discord REST API and web socket. If no explicit proxy is configured usingsetProxy(Proxy)
and no proxy selector is configured using this method,ProxySelector.getDefault()
is used to select appropriate proxies. IfProxySelector.setDefault(ProxySelector)
was not used to set a custom proxy selector, the default one evaluates the system propertieshttps.proxyHost
,https.proxyPort
,http.nonProxyHosts
,socksProxyHost
,socksProxyPort
andsocksProxyVersion
as documented on the Networking Properties page.Note: It is an error to configure both an explicit proxy via
setProxy(Proxy)
and a proxy selector using this method.- Parameters:
proxySelector
- The proxy selector to set.- Returns:
- The current instance in order to chain call methods.
- See Also:
setProxy(Proxy)
,setProxyAuthenticator(Authenticator)
,ProxySelector.getDefault()
,ProxySelector.setDefault(ProxySelector)
, Networking Properties
-
setProxy
public DiscordApiBuilder setProxy(java.net.Proxy proxy)
Sets the proxy which should be used to connect to the Discord REST API and web socket. If this is not set explicitly, the proxy selector configured withsetProxySelector(ProxySelector)
is used to select appropriate proxies. If both are not set,ProxySelector.getDefault()
is used to select appropriate proxies. IfProxySelector.setDefault(ProxySelector)
was not used to set a custom proxy selector, the default one evaluates the system propertieshttps.proxyHost
,https.proxyPort
,http.nonProxyHosts
,socksProxyHost
,socksProxyPort
andsocksProxyVersion
as documented on the Networking Properties page.Note: It is an error to configure both an explicit proxy using this method and a proxy selector using
setProxySelector(ProxySelector)
.- Parameters:
proxy
- The proxy to set.- Returns:
- The current instance in order to chain call methods.
- See Also:
setProxyAuthenticator(Authenticator)
,setProxySelector(ProxySelector)
,ProxySelector.getDefault()
,ProxySelector.setDefault(ProxySelector)
, Networking Properties
-
setProxyAuthenticator
public DiscordApiBuilder setProxyAuthenticator(Authenticator authenticator)
Sets the authenticator that should be used to authenticate against proxies that require it. If this is not set explicitly, the authenticator configured withAuthenticator.setDefault(java.net.Authenticator)
, if any, is used to get credentials forBasic
auth if the proxy supports it. If you need to support a more sophisticated authentication algorithm or scheme, use this method to set an own authenticator.- Parameters:
authenticator
- The proxy authenticator to set.- Returns:
- The current instance in order to chain call methods.
- See Also:
setProxy(Proxy)
,setProxySelector(ProxySelector)
,Authenticator.setDefault(java.net.Authenticator)
-
setTrustAllCertificates
public DiscordApiBuilder setTrustAllCertificates(boolean trustAllCertificates)
Sets whether all SSL certificates should be trusted when connecting to the Discord API and web socket. This might for example be necessary when connecting through a decrypting proxy. Be aware that this also increases the risk of man-in-the-middle attacks, which basically is, what a decrypting proxy does. Due to this risk, a warning is logged when connecting with this property set totrue
. If you do not care about this risk, you can suppress this warning using your logging configuration.- Parameters:
trustAllCertificates
- Whether to trust all SSL certificates.- Returns:
- The current instance in order to chain call methods.
-
setToken
public DiscordApiBuilder setToken(java.lang.String token)
Sets the token which is required for the login process. A tutorial on how to get the token can be found in the Javacord wiki.- Parameters:
token
- The token to set.- Returns:
- The current instance in order to chain call methods.
-
getToken
public java.util.Optional<java.lang.String> getToken()
Gets the token that will be used to login.- Returns:
- The token.
- See Also:
setToken(String)
-
setTotalShards
public DiscordApiBuilder setTotalShards(int totalShards)
Sets total shards for server sharding. Sharding allows you to split your bot into several independent instances. A shard only handles a subset of a bot's servers.- Parameters:
totalShards
- The total amount of shards. Sharding will be disabled if set to1
.- Returns:
- The current instance in order to chain call methods.
- See Also:
- API docs
-
getTotalShards
public int getTotalShards()
Gets the total amount of shards. Sharding is disabled if set to1
.- Returns:
- The total amount of shards.
- See Also:
setTotalShards(int)
-
setCurrentShard
public DiscordApiBuilder setCurrentShard(int currentShard)
Sets shard for server sharding. Sharding allows you to split your bot into several independent instances. A shard only handles a subset of a bot's servers.- Parameters:
currentShard
- The shard of this connection starting with0
!- Returns:
- The current instance in order to chain call methods.
- See Also:
- API docs
-
getCurrentShard
public int getCurrentShard()
Gets the current shard.- Returns:
- The current shard.
- See Also:
setCurrentShard(int)
-
setWaitForServersOnStartup
public DiscordApiBuilder setWaitForServersOnStartup(boolean waitForServersOnStartup)
Sets if Javacord should wait for all servers to become available on startup. If this is disabled theDiscordApi.getServers()
method will return an empty collection directly after logging in and fireServerBecomesAvailableEvent
events once they become available. You can check the ids of unavailable servers using theDiscordApi.getUnavailableServers()
method.- Parameters:
waitForServersOnStartup
- Whether Javacord should wait for all servers to become available on startup or not.- Returns:
- The current instance in order to chain call methods.
-
isWaitingForServersOnStartup
public boolean isWaitingForServersOnStartup()
Checks if Javacord should wait for all servers to become available on startup.- Returns:
- If Javacord should wait.
- See Also:
setWaitForServersOnStartup(boolean)
-
setWaitForUsersOnStartup
public DiscordApiBuilder setWaitForUsersOnStartup(boolean waitForUsersOnStartup)
Sets if Javacord should wait for all users to be cached. If this is set totrue
, Javacord will consider Servers with uncached users as unavailable.Requires the
Intent.GUILD_MEMBERS
intent to be set.- Parameters:
waitForUsersOnStartup
- Whether Javacord should wait for all users to be cached or not.- Returns:
- The current instance in order to chain call methods.
-
isWaitingForUsersOnStartup
public boolean isWaitingForUsersOnStartup()
Checks if Javacord should wait for all users to be cached.- Returns:
- If Javacord should wait.
- See Also:
setWaitForUsersOnStartup(boolean)
-
setShutdownHookRegistrationEnabled
public DiscordApiBuilder setShutdownHookRegistrationEnabled(boolean registerShutdownHook)
Sets if Javacord should register a shutdown hook that disconnects theDiscordApi
instance.By default, Javacord registers a shutdown hook using
Runtime.addShutdownHook(Thread)
that calls theDiscordApi.disconnect()
method. Setting this flag tofalse
will disable this behavior.- Parameters:
registerShutdownHook
- Whether the shutdown hook should be registered or not.- Returns:
- The current instance in order to chain call methods.
-
isShutdownHookRegistrationEnabled
public boolean isShutdownHookRegistrationEnabled()
Checks if newly createdDiscordApi
instances should register a shutdown hook to disconnect the instance.- Returns:
- Whether the shutdown hook will be registered or not.
- See Also:
setShutdownHookRegistrationEnabled(boolean)
-
setIntents
public DiscordApiBuilder setIntents(Intent... intents)
Sets intent for the events which should be received.- Parameters:
intents
- One or more intents fromIntent
.- Returns:
- The current instance in order to chain call methods.
-
setAllIntents
public DiscordApiBuilder setAllIntents()
Sets all intents.- Returns:
- The current instance in order to chain call methods.
-
setAllNonPrivilegedIntents
public DiscordApiBuilder setAllNonPrivilegedIntents()
Sets all non-privileged intents.This is the default behavior if no intents are set in the builder.
- Returns:
- The current instance in order to chain call methods.
-
setAllIntentsExcept
public DiscordApiBuilder setAllIntentsExcept(Intent... intentsToOmit)
Sets all intents except the given intents.- Parameters:
intentsToOmit
- One or moreIntent
s which should be omitted.- Returns:
- The current instance in order to chain call methods.
-
setAllNonPrivilegedIntentsExcept
public DiscordApiBuilder setAllNonPrivilegedIntentsExcept(Intent... intentsToOmit)
Sets all non privileged intents except the given intents.- Parameters:
intentsToOmit
- One or moreIntent
s which should be omitted.- Returns:
- The current instance in order to chain call methods.
-
setAllNonPrivilegedIntentsAnd
public DiscordApiBuilder setAllNonPrivilegedIntentsAnd(Intent... intentsToInclude)
Sets all non-privileged intents and the given intents.- Parameters:
intentsToInclude
- One or moreIntent
s which should be included.- Returns:
- The current instance in order to chain call methods.
-
addIntents
public DiscordApiBuilder addIntents(Intent... intents)
Adds the given intents to the already set.- Parameters:
intents
- The intents to add.- Returns:
- The current instance in order to chain call methods.
-
setAllIntentsWhere
public DiscordApiBuilder setAllIntentsWhere(java.util.function.Predicate<Intent> condition)
Sets the intents where the given predicate matches.- Parameters:
condition
- Whether the intent should be added or not.- Returns:
- The current instance in order to chain call methods.
-
setUserCacheEnabled
public DiscordApiBuilder setUserCacheEnabled(boolean enabled)
Sets whether the user cache should be enabled.By default, the user cache is disabled.
- Parameters:
enabled
- Whether the user cache should be enabled.- Returns:
- The current instance in order to chain call methods.
-
isUserCachedEnabled
public boolean isUserCachedEnabled()
Gets whether the user cache is enabled.- Returns:
- Whether the user cache is enabled.
-
setRecommendedTotalShards
public java.util.concurrent.CompletableFuture<DiscordApiBuilder> setRecommendedTotalShards()
Retrieves the recommended shards count from the Discord API and sets it in this builder. Sharding allows you to split your bot into several independent instances. A shard only handles a subset of a bot's servers.- Returns:
- A future with the current api builder.
- See Also:
- API docs
-
addListener
public <T extends GloballyAttachableListener> DiscordApiBuilder addListener(java.lang.Class<T> listenerClass, T listener)
Description copied from interface:ChainableGloballyAttachableListenerManager
Adds aGloballyAttachableListener
to all createdDiscordApi
instances. Adding a listener multiple times will only add it once. The order of invocation is according to first addition.- Specified by:
addListener
in interfaceChainableGloballyAttachableListenerManager
- Type Parameters:
T
- The type of the listener.- Parameters:
listenerClass
- The listener class.listener
- The listener to add.- Returns:
- The current instance in order to chain call methods.
-
addListener
public DiscordApiBuilder addListener(GloballyAttachableListener listener)
Description copied from interface:ChainableGloballyAttachableListenerManager
Adds a listener that implements one or moreGloballyAttachableListener
s to all createdDiscordApi
instances. Adding a listener multiple times will only add it once. The order of invocation is according to first addition.- Specified by:
addListener
in interfaceChainableGloballyAttachableListenerManager
- Parameters:
listener
- The listener to add.- Returns:
- The current instance in order to chain call methods.
-
addListener
public <T extends GloballyAttachableListener> DiscordApiBuilder addListener(java.lang.Class<T> listenerClass, java.util.function.Supplier<T> listenerSupplier)
Description copied from interface:ChainableGloballyAttachableListenerManager
Adds aGloballyAttachableListener
to all createdDiscordApi
instances. The supplier is called for every createdDiscordApi
instance, so either the same or different instances can be registered. One example would be a method reference to a default constructor likeMyListener::new
. Adding a listener multiple times will only add it once. The order of invocation is according to first addition.- Specified by:
addListener
in interfaceChainableGloballyAttachableListenerManager
- Type Parameters:
T
- The type of the listener.- Parameters:
listenerClass
- The listener class.listenerSupplier
- The supplier of listeners to add.- Returns:
- The current instance in order to chain call methods.
-
addListener
public DiscordApiBuilder addListener(java.util.function.Supplier<GloballyAttachableListener> listenerSupplier)
Description copied from interface:ChainableGloballyAttachableListenerManager
Adds a listener that implements one or moreGloballyAttachableListener
s to all createdDiscordApi
instances. The supplier is called for every createdDiscordApi
instance, so either the same or different instances can be registered. One example would be a method reference to a default constructor likeMyListener::new
. Adding a listener multiple times will only add it once. The order of invocation is according to first addition.- Specified by:
addListener
in interfaceChainableGloballyAttachableListenerManager
- Parameters:
listenerSupplier
- The supplier of listeners to add.- Returns:
- The current instance in order to chain call methods.
-
addListener
public <T extends GloballyAttachableListener> DiscordApiBuilder addListener(java.lang.Class<T> listenerClass, java.util.function.Function<DiscordApi,T> listenerFunction)
Description copied from interface:ChainableGloballyAttachableListenerManager
Adds aGloballyAttachableListener
to all createdDiscordApi
instances. The function is called for every createdDiscordApi
instance, so either the same or different instances can be registered. One example would be a method reference to a constructor with aDiscordApi
parameter likeMyListener::new
. Adding a listener multiple times will only add it once. The order of invocation is according to first addition.- Specified by:
addListener
in interfaceChainableGloballyAttachableListenerManager
- Type Parameters:
T
- The type of the listener.- Parameters:
listenerClass
- The listener class.listenerFunction
- The function to provide listeners to add.- Returns:
- The current instance in order to chain call methods.
-
addListener
public DiscordApiBuilder addListener(java.util.function.Function<DiscordApi,GloballyAttachableListener> listenerFunction)
Description copied from interface:ChainableGloballyAttachableListenerManager
Adds a listener that implements one or moreGloballyAttachableListener
s to all createdDiscordApi
instances. The function is called for every createdDiscordApi
instance, so either the same or different instances can be registered. One example would be a method reference to a constructor with aDiscordApi
parameter likeMyListener::new
. Adding a listener multiple times will only add it once. The order of invocation is according to first addition.- Specified by:
addListener
in interfaceChainableGloballyAttachableListenerManager
- Parameters:
listenerFunction
- The function to provide listeners to add.- Returns:
- The current instance in order to chain call methods.
-
removeListener
public DiscordApiBuilder removeListener(GloballyAttachableListener listener)
Description copied from interface:ChainableGloballyAttachableListenerManager
Removes a listener that implements one or moreGloballyAttachableListener
s from the list of listeners to be added toDiscordApi
instances. If the listener was already added to aDiscordApi
instance, it will not get removed by calling this method. This method should normally only be used before calling one of the login methods.- Specified by:
removeListener
in interfaceChainableGloballyAttachableListenerManager
- Parameters:
listener
- The listener to remove.- Returns:
- The current instance in order to chain call methods.
-
removeListener
public <T extends GloballyAttachableListener> DiscordApiBuilder removeListener(java.lang.Class<T> listenerClass, T listener)
Description copied from interface:ChainableGloballyAttachableListenerManager
Removes aGloballyAttachableListener
from the list of listeners to be added toDiscordApi
instances. If the listener was already added to aDiscordApi
instance, it will not get removed by calling this method. This method should normally only be used before calling one of the login methods.- Specified by:
removeListener
in interfaceChainableGloballyAttachableListenerManager
- Type Parameters:
T
- The type of the listener.- Parameters:
listenerClass
- The listener class.listener
- The listener to remove.- Returns:
- The current instance in order to chain call methods.
-
removeListenerSupplier
public DiscordApiBuilder removeListenerSupplier(java.util.function.Supplier<GloballyAttachableListener> listenerSupplier)
Description copied from interface:ChainableGloballyAttachableListenerManager
Removes a supplier of listeners that implements one or moreGloballyAttachableListener
s from the list of listeners to be added toDiscordApi
instances. If the listener was already added to aDiscordApi
instance, it will not get removed by calling this method. This method should normally only be used before calling one of the login methods.- Specified by:
removeListenerSupplier
in interfaceChainableGloballyAttachableListenerManager
- Parameters:
listenerSupplier
- The supplier of listeners to remove.- Returns:
- The current instance in order to chain call methods.
-
removeListenerSupplier
public <T extends GloballyAttachableListener> DiscordApiBuilder removeListenerSupplier(java.lang.Class<T> listenerClass, java.util.function.Supplier<T> listenerSupplier)
Description copied from interface:ChainableGloballyAttachableListenerManager
Removes a supplier ofGloballyAttachableListener
s from the list of listeners to be added toDiscordApi
instances. If the listener was already added to aDiscordApi
instance, it will not get removed by calling this method. This method should normally only be used before calling one of the login methods.- Specified by:
removeListenerSupplier
in interfaceChainableGloballyAttachableListenerManager
- Type Parameters:
T
- The type of the listener.- Parameters:
listenerClass
- The listener class.listenerSupplier
- The supplier of listeners to remove.- Returns:
- The current instance in order to chain call methods.
-
removeListenerFunction
public DiscordApiBuilder removeListenerFunction(java.util.function.Function<DiscordApi,GloballyAttachableListener> listenerFunction)
Description copied from interface:ChainableGloballyAttachableListenerManager
Removes a function that provides listeners that implements one or moreGloballyAttachableListener
s from the list of listeners to be added toDiscordApi
instances. If the listener was already added to aDiscordApi
instance, it will not get removed by calling this method. This method should normally only be used before calling one of the login methods.- Specified by:
removeListenerFunction
in interfaceChainableGloballyAttachableListenerManager
- Parameters:
listenerFunction
- The function to provide listeners to remove.- Returns:
- The current instance in order to chain call methods.
-
removeListenerFunction
public <T extends GloballyAttachableListener> DiscordApiBuilder removeListenerFunction(java.lang.Class<T> listenerClass, java.util.function.Function<DiscordApi,T> listenerFunction)
Description copied from interface:ChainableGloballyAttachableListenerManager
Removes a function that providesGloballyAttachableListener
s from the list of listeners to be added toDiscordApi
instances. If the listener was already added to aDiscordApi
instance, it will not get removed by calling this method. This method should normally only be used before calling one of the login methods.- Specified by:
removeListenerFunction
in interfaceChainableGloballyAttachableListenerManager
- Type Parameters:
T
- The type of the listener.- Parameters:
listenerClass
- The listener class.listenerFunction
- The function to provide listeners to remove.- Returns:
- The current instance in order to chain call methods.
-
-