JDA icon indicating copy to clipboard operation
JDA copied to clipboard

Add support for user-installable apps

Open freya022 opened this issue 1 year ago • 14 comments

Pull Request Etiquette

Changes

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

Closes Issue: NaN

Description

This adds support for user-installable apps (Preview, Release).

You are able to create application commands using the new properties, read the new data structures provided in ApplicationInfo, Interaction and Message, as well as responding to interactions in detached guilds (where your bot isn't it in) and group DMs.

Interesting elements include:

  • (Slash)CommandData#setContexts (Default: GUILD and BOT_DM)
  • (Slash)CommandData#setIntegrationTypes (Default: GUILD_INSTALL)
  • IDetachableEntity#isDetached (for Guild, Channel, Role, Member...)
  • Interaction#hasFullGuild
  • Interaction#getIntegrationOwners
  • Message#getInteractionMetadata

Note: The default contexts and integration types align with the current behavior, meaning there is no breaking change.

You can see examples here, you can also see the example changes in the Files changed tab.

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

freya022 avatar Mar 22 '24 19:03 freya022

There seems to be a caching issue If two different people use the same command in the same dm then all subsequent event.getUser() will return whoever used the command first.

Ran-Mewo avatar May 17 '24 03:05 Ran-Mewo

There seems to be a caching issue If two different people use the same command in the same dm then all subsequent event.getUser() will return whoever used the command first.

Should be fixed

freya022 avatar May 18 '24 16:05 freya022

I am not sure if this is an issue on my code or the library but updating attachments with editOriginalAttachments doesn't actually cause it to update unless you restart your discord

it's not an issue on my client as it also occurs for other people

Ran-Mewo avatar May 26 '24 09:05 Ran-Mewo

I am not sure if this is an issue on my code or the library but updating attachments with editOriginalAttachments doesn't actually cause it to update unless you restart your discord

it's not an issue on my client as it also occurs for other people

As you mentioned, restarting the client fixes the issue, so it's not a JDA issue

freya022 avatar May 26 '24 09:05 freya022

I really doubt it's not a JDA issue, it works in other discord frameworks Replying to an interaction using reply and then editing the original hook's attachments just doesn't work on JDA (well it does but discord doesn't update it)

sigh at this point I just give up, I have to resort to putting my image in an embed (by using .setImage("attachment://" + fileName)) I really hate how images in embeds get scaled down but that's a discord problem

the thing that annoys me the most is that it used to work, I don't know what changed nor do I know if it's something to do with your new changes

Ran-Mewo avatar May 26 '24 11:05 Ran-Mewo

Can't repro with the code below, please share minimal reproduction code if you can

public void onSlashReplyEditAttachment(SlashCommandInteractionEvent event, Message.Attachment attachment, Message.Attachment attachment2) throws Exception {
    final byte[] bytes = getBytes(attachment);
    final byte[] bytes2 = getBytes(attachment2);

    event.replyFiles(FileUpload.fromData(bytes, attachment.getFileName()))
            .setEphemeral(true) // Tried without ephemeral too
            .queue();

    event.getHook()
            .editOriginalAttachments(FileUpload.fromData(bytes2, attachment.getFileName()))
            .queue();
}

private byte[] getBytes(Message.Attachment attachment) throws Exception {
    try (InputStream stream = attachment.getProxy().download().get()) {
        return stream.readAllBytes();
    }
}

freya022 avatar May 27 '24 13:05 freya022

Maybe a UserJoinEvent(like GuildJoinEvent for userapps) and a JDA.getInstalledAppUsers()(like JDA.getGuilds() for userapps)

ErfinderLabyrinth avatar Jun 12 '24 16:06 ErfinderLabyrinth

Maybe a UserJoinEvent(like GuildJoinEvent for userapps) and a JDA.getInstalledAppUsers()(like JDA.getGuilds() for userapps)

Discord doesn't have a way to get who installed the application on their accounts

As a reminder, JDA adds what Discord documents, if it isn't in the Discord docs, we can't add it

freya022 avatar Jun 12 '24 16:06 freya022

I don't know if it's a limitation from Discord API, however, when trying to use SlashCommandInteractionEvent#getGuild().getLocale() on a command ran as user-app, it always returns ENGLISH_US, even when the server is a community server set to another locale. Tested on small and large servers

ErdbeerbaerLP avatar Jun 17 '24 09:06 ErdbeerbaerLP

I have been running this PR in production since 24/07 and I haven't found any issues, thanks freya! pets the freya

MrPowerGamerBR avatar Aug 17 '24 15:08 MrPowerGamerBR

Is this arriving any time soon?

loicfred avatar Sep 03 '24 13:09 loicfred

This will be merged once the maintainers have time to review it, in the meantime you can install a preview by following the instructions in the PR description

freya022 avatar Sep 03 '24 14:09 freya022

I'm running this fork since 25/8, @freya022 did a great job here, congrats and cheers!

Yuhtin avatar Sep 08 '24 04:09 Yuhtin

I got my bot using it in prod as well for most commands, working just fine

ErdbeerbaerLP avatar Sep 08 '24 06:09 ErdbeerbaerLP