Migrating from v3.2 to v3.3
This article should help you update your bot from Discord4J v3.2.x to v3.3.0. This new major release is over a year in the making and has lots of changes.
Before you start
If you encounter an issue while following this guide or discover something missing, feel free to suggest changes or discuss them in our server. Thanks!
Updating dependencies
Discord4J v3.3 depends on Reactor 2023 release train (Reactor Core 3.4.x and Reactor Netty 1.0.x). It maintains the JDK 8 baseline and includes other dependency upgrades like:
- discord-json 1.6 (from 1.5)
- jackson-databind 2.17 (from 2.12)
- jackson-datatype 2.17 (from 2.12)
- caffeine 2.9 (from 2.8)
- immutables 2.10 (from 2.9)
- jsr305 from com.google.code.findbugs 3.0 (new dependency)
Gradle
repositories {
mavenCentral()
}
dependencies {
implementation 'com.discord4j:discord4j-core:3.3.0'
}
Maven
<dependencies>
<dependency>
<groupId>com.discord4j</groupId>
<artifactId>discord4j-core</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
Changes in discord-json
Class rename
PositionModifyRequest: This class has been split into two classes,ChannelPositionModifyRequestandRolePositionModifyRequest
Class hierarchy changed
OnboardingData: This interface now extendsBaseOnboardingData. ThedefaultChannelIdsandenabledmethods were moved to the parent.OnboardingPromptData: This interface now extendsBaseOnboardingPromptData. Thetype,title,singleSelect,required, andinOnboardingmethods were moved to the parent.OnboardingPromptOptionData: This interface now extendsBaseOnboardingPromptOptionData. ThechannelsIds,rolesIds,title, anddescriptionmethods were moved to the parent.
Deprecation
ApplicationInfoData#summary: This field is deprecated and will be removed in Discord API v11. This field always returns an empty string.ApplicationCommandData#dmPermission: UseApplicationCommandData#contextsinstead
Field type change
-
ResolvedChannelData:name:String->Possible<Optional<String>>permissions:String->Possible<Optional<String>>
-
OnboardingPromptOptionData:emoji:EmojiData->Possible<EmojiData>
-
ApplicationInfoData:owner:UserData->Possible<PartialUserData>
-
ApplicationTeamMemberData:role:String->Possible<String>
-
PositionModifyRequest(nowChannelPositionModifyRequest):position:int->Possible<Optional<Integer>>
Changes in discord4j-core
Notable changes
- Update gateway API version to 10
- Calling any method that retrieves restricted data (message content, embeds, etc.) without enabling the
MESSAGE_CONTENTwill raise anUnsupportedOperationException - Created a new interface,
TopLevelGuildMessageWithThreadsChannelthat extendsTopLevelGuildMessageChannel, used forTextChannelandNewsChannel. This interface represents text channels that can have threads (AVoiceChannelis also aTopLevelGuildMessageChannelbut cannot have threads).
Signature changes
-
RestGuild#modifyChannelPositionsnow takes aList<ChannelPositionModifyRequest>as parameter -
RestGuild#modifyRolePositionsnow takes aList<RolePositionModifyRequest>as parameter -
GuildService#modifyGuildChannelPositionsnow takes aChannelPositionModifyRequest[]as parameter -
GuildService#modifyGuildRolePositionsnow takes aRolePositionModifyRequest[]as parameter -
MessageCreateSpec#messageReferencenow takes aPossible<MessageReferenceData>as parameter -
MessageCreateMono#withMessageReferencenow takes aPossible<MessageReferenceData>as parameter -
ApplicationTeamMember#getRoleno longer returnsnullfor the team owner, butTeamMemberRole.ADMIN -
ApplicationInfo#getOwnerIdnow returns anOptional<Snowflake> -
RestGuild#modifyChannelPositionsnow returns aFlux<Void> -
GuildService#modifyGuildChannelPositionsnow returns aFlux<Void> -
MessageBulkDeleteEvent#getChannelnow returns aMono<MessageChannel> -
VoiceState#getChannelnow returns aMono<AudioChannel> -
ResolvedChannel#getNamenow returns anOptional<String> -
ResolvedChannel#getEffectivePermissionsnow returns anOptional<PermissionSet> -
MessageChannel#getPinnedMessagesnow returns aPinnedMessagesQueryFluxwith a reference pinned message -
The
GuildEmojiclass now extendsEmoji -
The
Categoryclass now extendsBaseTopLevelGuildChannel -
The
GuildMessageChannelclass now extendsGuildChannel, MessageChannel -
The
PrivateChannelclass now extendsBaseChanneland implementsMessageChannel -
The
StoreChannelclass now extendsBaseTopLevelGuildChanneland implementsCategorizableChannel -
The
NewsChannelclass now extendsBaseTopLevelGuildChanneland implementsTopLevelGuildMessageWithThreadsChannel -
The
TextChannelclass now extendsBaseTopLevelGuildChanneland implementsTopLevelGuildMessageWithThreadsChannel -
The
VoiceChannelclass now extendsBaseTopLevelGuildChanneland implementsAudioChannel, TopLevelGuildMessageChannel -
The method
User#equalsis no longer final -
Renamed method
Guild#getGuildEmojiByIdtogetEmojiById -
Renamed
VoiceChannelJoinSpectoAudioChannelJoinSpec -
Renamed
VoiceChannelJoinMonotoAudioChannelJoinMono -
Renamed
ReactionEmojitoEmoji -
Removed field
Routes#NITRO_STICKER_PACKS_GET; useRoutes#STICKER_PACK_GET
Removed methods and classes
- Removed method
AutoModRule#edit(String name, EventType eventType, boolean enabled) - Removed method
ClientException#isRetryContextStatusCode - Removed deprecated method
Message#suppressEmbeds - Removed deprecated method
RestGuild#modifyOwnNickname - Removed deprecated method
ChannelService#suppressEmbeds - Removed
com.iwebpp.cryptoclasses - Removed class
BaseCategorizableChannel - Removed class
BaseGuildChannel - Removed class
BaseGuildMessageChannel - Removed class
BaseMessageChannel - Removed class
BaseTopLevelGuildMessageChannel - Removed deprecated field
Routes#MESSAGE_SUPPRESS_EMBEDS - Removed deprecated field
Routes#NICKNAME_MODIFY_OWN
Deprecations
- Deprecated method
IntegrationApplication#getSummary - Deprecated method
Guild#getFeatures(useGuild#getGuildFeatures) - Deprecated method
ApplicationInfo#isPublic(useApplicationInfo#isBotPublic) - Deprecated method
ApplicationInfo#requireCodeGrant(useApplicationInfo#botRequiresCodeGrant) - Deprecated method
ResolvedMember#getNicknameMention(This type of ping has been deprecated in the Discord API)
Other changes
- Using an
AutoModRuleEditMonoorAutoModRuleEditSpecno longer requires all fields to be set - Remove Reactor dependency as it is unused in this repo, replaced
reactor.util.annotation.*withjavax.annotation.*from jsr305 - Move classes in the encoding module to their own package (
discord4j.discordjson.encoding) due to package name clashing with api module (issue when linking both modules in a project declaring a module-info.java)
Internal validation when retrieving restricted data in Messages
Calling any method that retrieves restricted data (message content, embeds, etc.) without enabling the MESSAGE_CONTENT will raise an UnsupportedOperationException.
Make sure to enable the MESSAGE_CONTENT intent in the developer portal and in the client initialization.
For more information you can check the discord docs.
New Emoji structure
The ReactionEmoji class has been replaced by the Emoji class to handle the new emoji structure.
An emoji with an id is now a CustomEmoji, and can be one of two types:
GuildEmoji, for emojis created in a guildApplicationEmoji, for emojis created in an application via the api or the developer portal
Check more details about the API and behavior changes in What's new in v3.3.