JDA icon indicating copy to clipboard operation
JDA copied to clipboard

Add support for components V2

Open freya022 opened this issue 8 months ago • 6 comments

Pull Request Etiquette

Changes

  • [X] Internal code
  • [X] Library interface (affecting end-user code)
  • [X] Documentation
  • [ ] Other: _____

Closes Issue: NaN

Description

This adds the new component system (aka Components V2).

API docs:

  1. https://discord.com/developers/docs/change-log#introducing-new-components-for-messages
  2. https://discord.com/developers/docs/change-log#raised-component-limits
  3. https://discord.com/developers/docs/components/overview

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 pr command in the JDA Discord server. You can use the Update PR button to merge the latest changes if necessary (note that it may not update it if there are conflicts).

image

Migration (Preview)

I've written an OpenRewrite recipe to update most (if not all) breaking changes.

Requirements

  • Use a release JDA version (i.e., the group ID must be net.dv8tion)
  • Your current code must compile

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 rewriteDryRun task, this can be done by pressing CTRL twice on IntelliJ then running gradle rewriteDryRun. This will generate a diff file at build/reports/rewrite/rewrite.patch, you can check the possible changes there.

Applying changes

Run the rewriteRun task.

Maven
  1. Add the following repository:
<repository>
    <id>jitpack</id>
    <url>https://jitpack.io</url>
</repository>
  1. Add the following plugin:
<plugin>
  <groupId>org.openrewrite.maven</groupId>
  <artifactId>rewrite-maven-plugin</artifactId>
  <version>6.6.1</version>
  <configuration>
    <activeRecipes>
      <recipe>net.dv8tion.MigrateComponentsV2</recipe>
    </activeRecipes>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.openrewrite.recipe</groupId>
      <artifactId>rewrite-java-dependencies</artifactId>
      <version>1.32.1</version>
    </dependency>
    <dependency>
      <groupId>io.github.freya022</groupId>
      <artifactId>JDA</artifactId>
      <version>{{latest commit hash}}</version>
    </dependency>
  </dependencies>
</plugin>

Checking changes (dry run)

Run the rewrite:dryRun goal, this can be done by pressing CTRL twice on IntelliJ then running mvn 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:run goal.

You can then set the JDA dependency, as JDA 6.0.0 is not released.

It is recommended to optimize imports (Code | Optimize imports in IntelliJ) after migrating.

freya022 avatar Mar 07 '25 18:03 freya022

You're saying you have an issue but didn't describe what the issue is

freya022 avatar May 07 '25 20:05 freya022

@freya022 Seemed to be an issue on my side. Was just talking and just an hour after it founding it 😭

Reddishye avatar May 10 '25 13:05 Reddishye

Bump

douzooo avatar May 29 '25 12:05 douzooo

Is it intended that a TextDisplay can't be the first argument of a Section?

FelixTPG avatar Jun 01 '25 15:06 FelixTPG

Yes, a TextDisplay cannot be an accessory.

freya022 avatar Jun 01 '25 15:06 freya022

alright, thank you

FelixTPG avatar Jun 01 '25 15:06 FelixTPG

Minn sorting out

FelixTPG avatar Jun 30 '25 19:06 FelixTPG