discord-jda / JDA

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

Get invite code on member Join #804

Open YukioKeno opened 5 years ago

YukioKeno commented 5 years ago

General Troubleshooting

Issue

Issue Type

Description

Get info of the invite code when user join if they join via a invite link.

schnapster commented 5 years ago

This information is not available from the Discord API...yet.

See https://github.com/discordapp/discord-api-docs/issues/448

reflexin commented 5 years ago

I wrote a bot to do this with an algorithm, so it's still possible to create.

YukioKeno commented 5 years ago

And how do you code that?

BenjaminUrquhart commented 5 years ago

@YukioKeno

  1. Store how many times all invites have been used
  2. When a user joins, see which invite has a use incremented by 1
  3. That's probably the invite they used.
YukioKeno commented 5 years ago

Okay thank you. I'll try that :)

zaanposni commented 4 years ago

Note: I think this was not relevant in 2018 but nowadays you also have to check for missing invites in your new list as they could be expired by MaxUses. Furthermore, if there are two or more invites missing and only one of those had MaxUses, this is the invite that has been used. (The others expired by time)

If two or more invites are missing in your new list you cannot safely assign the used invite. This most likely happens if you forget to cache new invites on GuildInviteCreateEvent.

KaiKikuchi commented 9 months ago

Although I believe we still cannot get the invite code when a member joins, we can now get the invite code for a member with the new "member search" feature.

I hope we can at least get that, so that our bots can just search for the invite code when a new member joins the server. Thanks!

Related discussion comment: https://github.com/discord/discord-api-docs/discussions/3210#discussioncomment-7503972

MinnDevelopment commented 9 months ago

@KaiKikuchi bots cannot access this endpoint.

kohlerpop1 commented 7 months ago

This is now possible to retrieve via the API.

image image image Post body accepts json of how many users you want of 1000 maximum. Only required header: Authorization: Bot {Bot-Token} I believe this should be added to the member object as it is sent with every member now. Here is a sample response!

{
    "guild_id": "{guild-id}",
    "members": [
        {
            "member": {
                "avatar": null,
                "communication_disabled_until": null,
                "flags": 0,
                "joined_at": "2024-02-09T15:41:13.354000+00:00",
                "nick": null,
                "pending": false,
                "premium_since": null,
                "roles": [],
                "unusual_dm_activity_until": null,
                "user": {
                    "id": "example-id",
                    "username": "example-username",
                    "avatar": "2699fbf2e65df3ee85ecd2a84ce45cac",
                    "discriminator": "0",
                    "public_flags": 0,
                    "premium_type": 0,
                    "flags": 0,
                    "banner": null,
                    "accent_color": null,
                    "global_name": "Example Name",
                    "avatar_decoration_data": null,
                    "banner_color": null
                },
                "mute": false,
                "deaf": false
            },
            "source_invite_code": "XHVBNhMuUw",
            "join_source_type": 5,
            "inviter_id": "203200098426028526"
        }, {...}
    ],
    "page_result_count": 126,
    "total_result_count": 126
}

Originally found here: https://github.com/discord/discord-api-docs/discussions/3210?sort=old#:~:text=Bots%20can%20now%20access%20the%20source_invite_code

freya022 commented 7 months ago

Good chances it won't be added until it's documented

MinnDevelopment commented 7 months ago

This endpoint is still unfinished and not intended to be used in production. JDA does not support unfinished API features.

kohlerpop1 commented 7 months ago

Yep. I am aware both of what you are saying is correct however I wanted to make it visible to those who want/need to use it even before it is added to the JDA.