JDAService

@InterfacedService(acceptMultiple = false)
@MissingServiceMessage(message = "A service extending JDAService must exist and has to be in the search path")
abstract class JDAService(source)

Interfaced service to be implemented by the service which creates a JDA instance.

This has many advantages:

  • Checking gateway intents, cache flags, and member cache requirements for event listeners and event waiters

  • Conditionally enabling services based on gateway intents (@RequiredIntents), cache flags, and member cache

  • Starting JDA when every other service is ready

Usage

Register your instance as a service with @BService or any annotation that enables your class for dependency injection.

Example:

@BService
class Bot(private val config: Config) : JDAService() {
// Default intents + MESSAGE_CONTENT
override val intents: Set<GatewayIntent> = defaultIntents(GatewayIntent.MESSAGE_CONTENT)

override val cacheFlags: Set<CacheFlag> = enumSetOf()

override fun createJDA(event: BReadyEvent, eventManager: IEventManager) {
// Read the docs on what this does
lightSharded(config.token, ...) {
...
}
}
}

Spring support

Spring users must set their gateway intents and cache flags using properties, named jda.intents and jda.cacheFlags respectively, also available in JDAConfiguration.

See also

JDAService.createJDA

@InterfacedService

@RequiredIntents

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val cacheFlags: Set<CacheFlag>

The cache flags used by your bot, the provided cache flags must all be present in JDA.getCacheFlags.

Link copied to clipboard
abstract val intents: Set<GatewayIntent>

The intents used by your bot, must be passed as the entire list of intents your bot will use, i.e., JDABuilder's create(Light/Default) methods and similar for shard managers, do not use JDABuilder.enableIntents.

Functions

Link copied to clipboard
Link copied to clipboard
inline fun JDAService.create(token: String, memberCachePolicy: MemberCachePolicy? = null, chunkingFilter: ChunkingFilter? = null, activity: Activity? = null, restConfig: RestConfig? = getDefaultRestConfig(), block: JDABuilder.() -> Unit = {}): JDA
Link copied to clipboard
inline fun JDAService.createSharded(token: String, shardRange: IntRange? = null, shardsTotal: Int = -1, login: Boolean = true, memberCachePolicy: MemberCachePolicy? = null, chunkingFilter: ChunkingFilter? = null, noinline activityProvider: (shardId: Int) -> Activity? = null, restConfig: RestConfig? = getDefaultRestConfig(), block: DefaultShardManagerBuilder.() -> Unit = {}): ShardManager
Link copied to clipboard
Link copied to clipboard
inline fun JDAService.default(token: String, memberCachePolicy: MemberCachePolicy? = null, chunkingFilter: ChunkingFilter? = null, activity: Activity? = null, restConfig: RestConfig? = getDefaultRestConfig(), block: JDABuilder.() -> Unit = {}): JDA
Link copied to clipboard
inline fun JDAService.defaultSharded(token: String, shardRange: IntRange? = null, shardsTotal: Int = -1, login: Boolean = true, memberCachePolicy: MemberCachePolicy? = null, chunkingFilter: ChunkingFilter? = null, noinline activityProvider: (shardId: Int) -> Activity? = null, restConfig: RestConfig? = getDefaultRestConfig(), block: DefaultShardManagerBuilder.() -> Unit = {}): ShardManager
Link copied to clipboard
@CheckReturnValue
fun light(token: String): JDABuilder
Link copied to clipboard
inline fun JDAService.light(token: String, memberCachePolicy: MemberCachePolicy? = null, chunkingFilter: ChunkingFilter? = null, activity: Activity? = null, restConfig: RestConfig? = getDefaultRestConfig(), block: JDABuilder.() -> Unit = {}): JDA
Link copied to clipboard
inline fun JDAService.lightSharded(token: String, shardRange: IntRange? = null, shardsTotal: Int = -1, login: Boolean = true, memberCachePolicy: MemberCachePolicy? = null, chunkingFilter: ChunkingFilter? = null, noinline activityProvider: (shardId: Int) -> Activity? = null, restConfig: RestConfig? = getDefaultRestConfig(), block: DefaultShardManagerBuilder.() -> Unit = {}): ShardManager