Class DiscordApiBuilder
- java.lang.Object
-
- org.javacord.api.DiscordApiBuilder
-
- All Implemented Interfaces:
ChainableGloballyAttachableListenerManager
public class DiscordApiBuilder extends 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 <T extends GloballyAttachableListener>
DiscordApiBuilderaddListener(Class<T> listenerClass, Function<DiscordApi,T> listenerFunction)Adds aGloballyAttachableListenerto all createdDiscordApiinstances.<T extends GloballyAttachableListener>
DiscordApiBuilderaddListener(Class<T> listenerClass, Supplier<T> listenerSupplier)Adds aGloballyAttachableListenerto all createdDiscordApiinstances.<T extends GloballyAttachableListener>
DiscordApiBuilderaddListener(Class<T> listenerClass, T listener)Adds aGloballyAttachableListenerto all createdDiscordApiinstances.DiscordApiBuilderaddListener(Function<DiscordApi,GloballyAttachableListener> listenerFunction)Adds a listener that implements one or moreGloballyAttachableListeners to all createdDiscordApiinstances.DiscordApiBuilderaddListener(Supplier<GloballyAttachableListener> listenerSupplier)Adds a listener that implements one or moreGloballyAttachableListeners to all createdDiscordApiinstances.DiscordApiBuilderaddListener(GloballyAttachableListener listener)Adds a listener that implements one or moreGloballyAttachableListeners to all createdDiscordApiinstances.AccountTypegetAccountType()Gets the account type.intgetCurrentShard()Gets the current shard.Optional<String>getToken()Gets the token that will be used to login.intgetTotalShards()Gets the total amount of shards.booleanisShutdownHookRegistrationEnabled()Checks if newly createdDiscordApiinstances should register a shutdown hook to disconnect the instance.booleanisWaitingForServersOnStartup()Checks if Javacord should wait for all servers to become available on startup.booleanisWaitingForUsersOnStartup()Checks if Javacord should wait for all users to be cached.CompletableFuture<DiscordApi>login()Login to the account with the given token.Collection<CompletableFuture<DiscordApi>>loginAllShards()Login all shards to the account with the given token.Collection<CompletableFuture<DiscordApi>>loginShards(int... shards)Login given shards to the account with the given token.Collection<CompletableFuture<DiscordApi>>loginShards(IntPredicate shardsCondition)Login shards adhering to the given predicate to the account with the given token.<T extends GloballyAttachableListener>
DiscordApiBuilderremoveListener(Class<T> listenerClass, T listener)Removes aGloballyAttachableListenerfrom the list of listeners to be added toDiscordApiinstances.DiscordApiBuilderremoveListener(GloballyAttachableListener listener)Removes a listener that implements one or moreGloballyAttachableListeners from the list of listeners to be added toDiscordApiinstances.<T extends GloballyAttachableListener>
DiscordApiBuilderremoveListenerFunction(Class<T> listenerClass, Function<DiscordApi,T> listenerFunction)Removes a function that providesGloballyAttachableListeners from the list of listeners to be added toDiscordApiinstances.DiscordApiBuilderremoveListenerFunction(Function<DiscordApi,GloballyAttachableListener> listenerFunction)Removes a function that provides listeners that implements one or moreGloballyAttachableListeners from the list of listeners to be added toDiscordApiinstances.<T extends GloballyAttachableListener>
DiscordApiBuilderremoveListenerSupplier(Class<T> listenerClass, Supplier<T> listenerSupplier)Removes a supplier ofGloballyAttachableListeners from the list of listeners to be added toDiscordApiinstances.DiscordApiBuilderremoveListenerSupplier(Supplier<GloballyAttachableListener> listenerSupplier)Removes a supplier of listeners that implements one or moreGloballyAttachableListeners from the list of listeners to be added toDiscordApiinstances.DiscordApiBuildersetAccountType(AccountType type)Sets the account type.DiscordApiBuildersetAllIntents()Sets all intents.DiscordApiBuildersetAllIntentsExcept(Intent... intentsToOmit)Sets all intents except the given intents.DiscordApiBuildersetAllIntentsWhere(Predicate<Intent> condition)Sets the intents where the given predicate matches.DiscordApiBuildersetAllNonPrivilegedIntents()Sets all non privileged intents.DiscordApiBuildersetAllNonPrivilegedIntentsExcept(Intent... intentsToOmit)Sets all non privileged intents except the given intents.DiscordApiBuildersetCurrentShard(int currentShard)Sets shard for server sharding.DiscordApiBuildersetGatewayIdentifyRatelimiter(Ratelimiter ratelimiter)Sets a ratelimiter that can be used to control the 5 seconds gateway identify ratelimit.DiscordApiBuildersetGlobalRatelimiter(Ratelimiter ratelimiter)Sets a ratelimiter that can be used to control global ratelimits.DiscordApiBuildersetIntents(Intent... intents)Sets intent for the events which should be received.DiscordApiBuildersetProxy(Proxy proxy)Sets the proxy which should be used to connect to the Discord REST API and web socket.DiscordApiBuildersetProxyAuthenticator(Authenticator authenticator)Sets the authenticator that should be used to authenticate against proxies that require it.DiscordApiBuildersetProxySelector(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.CompletableFuture<DiscordApiBuilder>setRecommendedTotalShards()Retrieves the recommended shards count from the Discord API and sets it in this builder.DiscordApiBuildersetShutdownHookRegistrationEnabled(boolean registerShutdownHook)Sets if Javacord should register a shutdown hook that disconnects theDiscordApiinstance.DiscordApiBuildersetToken(String token)Sets the token which is required for the login process.DiscordApiBuildersetTotalShards(int totalShards)Sets total shards for server sharding.DiscordApiBuildersetTrustAllCertificates(boolean trustAllCertificates)Sets whether all SSL certificates should be trusted when connecting to the Discord API and web socket.DiscordApiBuildersetWaitForServersOnStartup(boolean waitForServersOnStartup)Sets if Javacord should wait for all servers to become available on startup.DiscordApiBuildersetWaitForUsersOnStartup(boolean waitForUsersOnStartup)Sets if Javacord should wait for all users to be cached.-
Methods inherited from interface org.javacord.api.listener.ChainableGloballyAttachableListenerManager
addAudioSourceFinishedListener, addAudioSourceFinishedListener, addAudioSourceFinishedListener, addCachedMessagePinListener, addCachedMessagePinListener, addCachedMessagePinListener, addCachedMessageUnpinListener, addCachedMessageUnpinListener, addCachedMessageUnpinListener, addChannelPinsUpdateListener, addChannelPinsUpdateListener, addChannelPinsUpdateListener, addGroupChannelChangeNameListener, addGroupChannelChangeNameListener, addGroupChannelChangeNameListener, addGroupChannelCreateListener, addGroupChannelCreateListener, addGroupChannelCreateListener, addGroupChannelDeleteListener, addGroupChannelDeleteListener, addGroupChannelDeleteListener, addKnownCustomEmojiChangeNameListener, addKnownCustomEmojiChangeNameListener, addKnownCustomEmojiChangeNameListener, addKnownCustomEmojiChangeWhitelistedRolesListener, addKnownCustomEmojiChangeWhitelistedRolesListener, addKnownCustomEmojiChangeWhitelistedRolesListener, addKnownCustomEmojiCreateListener, addKnownCustomEmojiCreateListener, addKnownCustomEmojiCreateListener, addKnownCustomEmojiDeleteListener, addKnownCustomEmojiDeleteListener, addKnownCustomEmojiDeleteListener, addLostConnectionListener, addLostConnectionListener, addLostConnectionListener, addMessageCreateListener, addMessageCreateListener, addMessageCreateListener, addMessageDeleteListener, addMessageDeleteListener, addMessageDeleteListener, addMessageEditListener, addMessageEditListener, addMessageEditListener, 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, 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, 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, addServerMemberUnbanListener, addServerMemberUnbanListener, addServerMemberUnbanListener, addServerStageVoiceChannelChangeTopicListener, addServerStageVoiceChannelChangeTopicListener, addServerStageVoiceChannelChangeTopicListener, addServerTextChannelChangeSlowmodeListener, addServerTextChannelChangeSlowmodeListener, addServerTextChannelChangeSlowmodeListener, addServerTextChannelChangeTopicListener, addServerTextChannelChangeTopicListener, addServerTextChannelChangeTopicListener, addServerVoiceChannelChangeBitrateListener, addServerVoiceChannelChangeBitrateListener, addServerVoiceChannelChangeBitrateListener, addServerVoiceChannelChangeUserLimitListener, addServerVoiceChannelChangeUserLimitListener, addServerVoiceChannelChangeUserLimitListener, addServerVoiceChannelMemberJoinListener, addServerVoiceChannelMemberJoinListener, addServerVoiceChannelMemberJoinListener, addServerVoiceChannelMemberLeaveListener, addServerVoiceChannelMemberLeaveListener, addServerVoiceChannelMemberLeaveListener, addUserChangeActivityListener, addUserChangeActivityListener, addUserChangeActivityListener, addUserChangeAvatarListener, addUserChangeAvatarListener, addUserChangeAvatarListener, addUserChangeDeafenedListener, addUserChangeDeafenedListener, addUserChangeDeafenedListener, addUserChangeDiscriminatorListener, addUserChangeDiscriminatorListener, addUserChangeDiscriminatorListener, addUserChangeMutedListener, addUserChangeMutedListener, addUserChangeMutedListener, addUserChangeNameListener, addUserChangeNameListener, addUserChangeNameListener, addUserChangeNicknameListener, addUserChangeNicknameListener, addUserChangeNicknameListener, addUserChangeSelfDeafenedListener, addUserChangeSelfDeafenedListener, addUserChangeSelfDeafenedListener, addUserChangeSelfMutedListener, addUserChangeSelfMutedListener, addUserChangeSelfMutedListener, addUserChangeStatusListener, addUserChangeStatusListener, addUserChangeStatusListener, addUserRoleAddListener, addUserRoleAddListener, addUserRoleAddListener, addUserRoleRemoveListener, addUserRoleRemoveListener, addUserRoleRemoveListener, addUserStartTypingListener, addUserStartTypingListener, addUserStartTypingListener, addVoiceServerUpdateListener, addVoiceServerUpdateListener, addVoiceServerUpdateListener, addVoiceStateUpdateListener, addVoiceStateUpdateListener, addVoiceStateUpdateListener, addWebhooksUpdateListener, addWebhooksUpdateListener, addWebhooksUpdateListener
-
-
-
-
Method Detail
-
login
public CompletableFuture<DiscordApi> login()
Login to the account with the given token.- Returns:
- A
CompletableFuturewhich contains the DiscordApi.
-
loginAllShards
public Collection<CompletableFuture<DiscordApi>> loginAllShards()
Login all shards to the account with the given token. It is invalid to callsetCurrentShard(int)with anything but0before calling this method.- Returns:
- A collection of
CompletableFutures which contain theDiscordApis for the shards.
-
loginShards
public Collection<CompletableFuture<DiscordApi>> loginShards(IntPredicate shardsCondition)
Login shards adhering to the given predicate to the account with the given token. It is invalid to callsetCurrentShard(int)with anything but0before calling this method.- Parameters:
shardsCondition- The predicate for identifying shards to connect, starting with0!- Returns:
- A collection of
CompletableFutures which contain theDiscordApis for the shards.
-
loginShards
public Collection<CompletableFuture<DiscordApi>> loginShards(int... shards)
Login given shards to the account with the given token. It is invalid to callsetCurrentShard(int)with anything but0before calling this method.- Parameters:
shards- The shards to connect, starting with0!- Returns:
- A collection of
CompletableFutures which contain theDiscordApis for the shards.
-
setGlobalRatelimiter
public DiscordApiBuilder setGlobalRatelimiter(Ratelimiter ratelimiter)
Sets a ratelimiter that can be used to control global ratelimits.By default, no ratelimiter is set, but for large bots or special use-cases, it can be useful to provide a ratelimiter with a hardcoded ratelimit to prevent hitting the global ratelimit.
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
LocalRatelimiterwhich 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, phyiscal 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.
-
setProxySelector
public DiscordApiBuilder setProxySelector(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,socksProxyPortandsocksProxyVersionas documented on the Networking Properties page.Note: It is an error to configure 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(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,socksProxyPortandsocksProxyVersionas documented on the Networking Properties page.Note: It is an error to configure 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 forBasicauth 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(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 Optional<String> getToken()
Gets the token that will be used to login.- Returns:
- The token.
- See Also:
setToken(String)
-
setAccountType
public DiscordApiBuilder setAccountType(AccountType type)
Sets the account type. By default the builder assumes that you want to login to a bot account. Please notice, that public client bots are not allowed by Discord!- Parameters:
type- The account type.- Returns:
- The current instance in order to chain call methods.
-
getAccountType
public AccountType getAccountType()
Gets the account type.- Returns:
- The account type.
- See Also:
setAccountType(AccountType)
-
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 fireServerBecomesAvailableEventevents 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_MEMBERSintent 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 theDiscordApiinstance.By default, Javacord registers a shutdown hook using
Runtime.addShutdownHook(Thread)that calls theDiscordApi.disconnect()method. Setting this flag tofalsewill 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 createdDiscordApiinstances 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 moreIntents 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 moreIntents which should be omitted.- Returns:
- The current instance in order to chain call methods.
-
setAllIntentsWhere
public DiscordApiBuilder setAllIntentsWhere(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.
-
setRecommendedTotalShards
public 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(Class<T> listenerClass, T listener)
Description copied from interface:ChainableGloballyAttachableListenerManagerAdds aGloballyAttachableListenerto all createdDiscordApiinstances. Adding a listener multiple times will only add it once. The order of invocation is according to first addition.- Specified by:
addListenerin 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:ChainableGloballyAttachableListenerManagerAdds a listener that implements one or moreGloballyAttachableListeners to all createdDiscordApiinstances. Adding a listener multiple times will only add it once. The order of invocation is according to first addition.- Specified by:
addListenerin interfaceChainableGloballyAttachableListenerManager- Parameters:
listener- The listener to add.- Returns:
- The current instance in order to chain call methods.
-
addListener
public <T extends GloballyAttachableListener> DiscordApiBuilder addListener(Class<T> listenerClass, Supplier<T> listenerSupplier)
Description copied from interface:ChainableGloballyAttachableListenerManagerAdds aGloballyAttachableListenerto all createdDiscordApiinstances. The supplier is called for every createdDiscordApiinstance, 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:
addListenerin 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(Supplier<GloballyAttachableListener> listenerSupplier)
Description copied from interface:ChainableGloballyAttachableListenerManagerAdds a listener that implements one or moreGloballyAttachableListeners to all createdDiscordApiinstances. The supplier is called for every createdDiscordApiinstance, 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:
addListenerin 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(Class<T> listenerClass, Function<DiscordApi,T> listenerFunction)
Description copied from interface:ChainableGloballyAttachableListenerManagerAdds aGloballyAttachableListenerto all createdDiscordApiinstances. The function is called for every createdDiscordApiinstance, so either the same or different instances can be registered. One example would be a method reference to a constructor with aDiscordApiparameter likeMyListener::new. Adding a listener multiple times will only add it once. The order of invocation is according to first addition.- Specified by:
addListenerin 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(Function<DiscordApi,GloballyAttachableListener> listenerFunction)
Description copied from interface:ChainableGloballyAttachableListenerManagerAdds a listener that implements one or moreGloballyAttachableListeners to all createdDiscordApiinstances. The function is called for every createdDiscordApiinstance, so either the same or different instances can be registered. One example would be a method reference to a constructor with aDiscordApiparameter likeMyListener::new. Adding a listener multiple times will only add it once. The order of invocation is according to first addition.- Specified by:
addListenerin 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:ChainableGloballyAttachableListenerManagerRemoves a listener that implements one or moreGloballyAttachableListeners from the list of listeners to be added toDiscordApiinstances. If the listener was already added to aDiscordApiinstance, 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:
removeListenerin interfaceChainableGloballyAttachableListenerManager- Parameters:
listener- The listener to remove.- Returns:
- The current instance in order to chain call methods.
-
removeListener
public <T extends GloballyAttachableListener> DiscordApiBuilder removeListener(Class<T> listenerClass, T listener)
Description copied from interface:ChainableGloballyAttachableListenerManagerRemoves aGloballyAttachableListenerfrom the list of listeners to be added toDiscordApiinstances. If the listener was already added to aDiscordApiinstance, 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:
removeListenerin 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(Supplier<GloballyAttachableListener> listenerSupplier)
Description copied from interface:ChainableGloballyAttachableListenerManagerRemoves a supplier of listeners that implements one or moreGloballyAttachableListeners from the list of listeners to be added toDiscordApiinstances. If the listener was already added to aDiscordApiinstance, 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:
removeListenerSupplierin 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(Class<T> listenerClass, Supplier<T> listenerSupplier)
Description copied from interface:ChainableGloballyAttachableListenerManagerRemoves a supplier ofGloballyAttachableListeners from the list of listeners to be added toDiscordApiinstances. If the listener was already added to aDiscordApiinstance, 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:
removeListenerSupplierin 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(Function<DiscordApi,GloballyAttachableListener> listenerFunction)
Description copied from interface:ChainableGloballyAttachableListenerManagerRemoves a function that provides listeners that implements one or moreGloballyAttachableListeners from the list of listeners to be added toDiscordApiinstances. If the listener was already added to aDiscordApiinstance, 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:
removeListenerFunctionin 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(Class<T> listenerClass, Function<DiscordApi,T> listenerFunction)
Description copied from interface:ChainableGloballyAttachableListenerManagerRemoves a function that providesGloballyAttachableListeners from the list of listeners to be added toDiscordApiinstances. If the listener was already added to aDiscordApiinstance, 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:
removeListenerFunctionin 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.
-
-