v5.0.0-beta.7 | Customize Rate-Limiter
Overview
You can now use RestConfig
to customize parts of the REST handling in JDA. This allows you to create custom rate-limiter implementations and make use of rate-limit proxy services such as http-proxy.
Rate-Limiter Customization (#2307)
Using RestConfig, you can change parts of the REST handling. This allows you to append to the User-Agent, add custom headers, or even completely replace the existing Rate-Limiter handling:
RestConfig config = new RestConfig();
config.setUserAgentSuffix("custom suffix"); // Changes user-agent to "DiscordBot(JDA, ...) custom suffix"
config.setBaseUrl("https://proxy.example.com/api/v10"); // requests will now go through this endpoint, allowing custom rate-limits
config.setRateLimiterFactory(...); // change the handling of rate-limits
builder.setRestConfig(config); // then simply set it on your JDABuilder or DefaultShardManagerBuilder
This can also be useful to implement a different queue system for rate-limit handling. By default, JDA will always use the SequentialRateLimiter, which handles requests to the same rate-limit bucket in sequence to avoid messages being unordered. A custom implementation could replace this to run requests in parallel.
To implement a custom rate-limiter, use the existing RestRateLimiter interface and implement the required methods as documented. Your implementation will be provided with Work instances to handle.
Member Flags (#2417)
You can now access the flags on members and modify them. This allows to check if a member has rejoined the guild or passed onboarding. The rejoin flag is not entirely reliable, since Discord has only started tracking rejoins recently. Members who rejoined years ago will not have this flag set.
With Member#modifyFlags
, you can change some of these flags. Only a subset of the existing flags are modifiable.
EnumSet<MemberFlag> flags = member.getFlags();
flags.add(MemberFlag.BYPASS_VERIFICATION); // Member bypasses verification level on guild
member.modifyFlags(flags).queue();
Features
- Add rate-limiter customization by @MinnDevelopment in #2307
- Add support for member flags by @MinnDevelopment in #2417
Changes
- Remove AccountType by @MinnDevelopment in #2420
- Handle new channel field on interactions by @MinnDevelopment in #2436
Bug Fixes
- Fix channel manager not using right type by @MinnDevelopment in #2428
Full Changelog: v5.0.0-beta.6...v5.0.0-beta.7
Installation
Gradle
repositories {
mavenCentral()
}
dependencies {
implementation("net.dv8tion:JDA:5.0.0-beta.7")
}
Maven
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>5.0.0-beta.7</version>
</dependency>