discord-jda / JDA

Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Apache License 2.0
4.28k stars 737 forks source link

Add support for user-installable apps #2633

Open freya022 opened 5 months ago

freya022 commented 5 months ago

Pull Request Etiquette

Changes

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:

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

Ran-Mewo commented 3 months ago

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.

freya022 commented 3 months ago

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

Ran-Mewo commented 3 months ago

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

freya022 commented 3 months ago

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

Ran-Mewo commented 3 months ago

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

freya022 commented 3 months ago

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();
    }
}
ErfinderLabyrinth commented 3 months ago

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

freya022 commented 3 months ago

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

ErdbeerbaerLP commented 2 months ago

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

MrPowerGamerBR commented 3 weeks ago

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

LoicMaitreDuFeu commented 1 week ago

Is this arriving any time soon?

freya022 commented 1 week ago

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

Yuhtin commented 5 days ago

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

ErdbeerbaerLP commented 5 days ago

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