Add support for components V2#2809
Merged
MinnDevelopment merged 308 commits intoJul 13, 2025
Merged
Conversation
3 tasks
e3ed5e3 to
cf0c7ef
Compare
7166b9d to
c4790ff
Compare
| @Override | ||
| public DataObject toData() | ||
| { | ||
| final String fileName = Helpers.getLastPathSegment(media.getUrl()); |
Contributor
There was a problem hiding this comment.
This causes a NullPointerException when creating a message that has a media gallery item
jda-ktx calls MediaGalleryItem.fromUrl(url), which that calls the MediaGalleryItemImpl(String url) constructor, and the media parameter is set to null
final String mediaUrl;
if (this.media != null) {
final String fileName = Helpers.getLastPathSegment(media.getUrl());
mediaUrl = "attachment://" + fileName;
} else {
mediaUrl = this.url;
}
return DataObject.empty()
.put("media", DataObject.empty().put("url", mediaUrl))
.put("description", description)
.put("spoiler", spoiler);
Contributor
There was a problem hiding this comment.
Keep in mind that there is also other NPE related to the media.getUrl() change, here's another stacktrace
java.lang.NullPointerException: Cannot invoke "net.dv8tion.jda.api.components.ResolvedMedia.getUrl()" because "this.media" is null
at net.dv8tion.jda.internal.components.mediagallery.MediaGalleryItemImpl.getFiles(MediaGalleryItemImpl.java:98)
at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:273)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:276)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1939)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at net.dv8tion.jda.api.utils.messages.MessageEditData.getAdditionalFiles(MessageEditData.java:373)
at net.dv8tion.jda.api.utils.messages.MessageEditData.toData(MessageEditData.java:339)
at net.dv8tion.jda.internal.requests.restaction.WebhookMessageEditActionImpl.finalizeData(WebhookMessageEditActionImpl.java:56)
at net.dv8tion.jda.internal.requests.RestActionImpl.submit(RestActionImpl.java:212)
at net.dv8tion.jda.internal.requests.restaction.TriggerRestAction.submit(TriggerRestAction.java:123)
at net.dv8tion.jda.api.requests.RestAction.submit(RestAction.java:703)
at net.perfectdreams.loritta.morenitta.utils.extensions.JDAExtensionsKt.await(JDAExtensions.kt:34)
at net.perfectdreams.loritta.morenitta.interactions.UnleashedHook$InteractionHook.editOriginal(UnleashedHook.kt:12)
at net.perfectdreams.loritta.morenitta.interactions.UnleashedHook$InteractionHook.editOriginal(UnleashedHook.kt:15)
at net.perfectdreams.loritta.morenitta.interactions.vanilla.fun.GiveawayBuilderScreen$Appearance$render$editGiveawayImageButton$1.invokeSuspend(GiveawayBuilderScreen.kt:477)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith$$$capture(ContinuationImpl.kt:33)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:829)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)
```
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
So it can be immutable later
Removes unnecessary Modal.Builder#addComponents
Override when children needs to be inspected
ActionRow also got isValid, getActionComponents and getButtons
This was referenced Jul 1, 2025
Co-authored-by: MinnDevelopment <[email protected]>
Co-authored-by: MinnDevelopment <[email protected]>
Asking for unions is unnecessary, they will be cast anyway
- Ensure no empty list is passed - Add each component in the currently built row
Co-authored-by: MinnDevelopment <[email protected]>
This reverts commit 325c55d.
Co-authored-by: MinnDevelopment <[email protected]>
MinnDevelopment
approved these changes
Jul 13, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Etiquette
Changes
Closes Issue: NaN
Description
This adds the new component system (aka Components V2).
API docs:
Examples: ComponentsV2Example.java
Make sure to give your opinion on the JDA dev thread.
Supersedes #2806.
Installation (Preview)
You can use the "Using new features" guide from the JDA wiki.
Alternatively, you can get the newest version for your favorite tool, by using the
/jitpack prcommand in the JDA Discord server. You can use theUpdate PRbutton to merge the latest changes if necessary (note that it may not update it if there are conflicts).Migration (Preview)
I've written an OpenRewrite recipe to update most (if not all) breaking changes.
Requirements
net.dv8tion)Usage
As with any migration tool, it is highly recommended to commit/push your changes before doing anything.
Note: Kotlin 2.X is not supported by OpenRewrite yet, however 1.X should work.
(Kotlin) Gradle
plugins { // ... id("org.openrewrite.rewrite") version "7.4.1" } repositories { // ... maven("https://jitpack.io") } dependencies { // Existing JDA dependency // ... rewrite("io.github.freya022:JDA:{{latest commit hash}}") rewrite("org.openrewrite.recipe:rewrite-java-dependencies:1.32.1") } rewrite { activeRecipe("net.dv8tion.MigrateComponentsV2") }Checking changes (dry run)
Run the
rewriteDryRuntask, this can be done by pressing CTRL twice on IntelliJ then runninggradle rewriteDryRun.This will generate a diff file at
build/reports/rewrite/rewrite.patch, you can check the possible changes there.Applying changes
Run the
rewriteRuntask.Maven
Checking changes (dry run)
Run the
rewrite:dryRungoal, this can be done by pressing CTRL twice on IntelliJ then runningmvn rewrite:dryRun.This will generate a diff file at
target/site/rewrite/rewrite.patch, you can check the possible changes there.Applying changes
Run the
rewrite:rungoal.You can then set the JDA dependency, as JDA 6.0.0 is not released.
It is recommended to optimize imports (
Code | Optimize importsin IntelliJ) after migrating.