JDA icon indicating copy to clipboard operation
JDA copied to clipboard

Get invite code on member Join

Open YukioKeno opened this issue 5 years ago • 12 comments

General Troubleshooting

  • [x] I have checked for similar issues.
  • [x] I have updated to the latest JDA version.
  • [x] I have checked the branches or the maintainers' PRs for upcoming features/bug fixes.

Issue

Issue Type

  • [ ] Bug Report
  • [x] Feature Request

Description

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

YukioKeno avatar Oct 14 '18 13:10 YukioKeno

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

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

schnapster avatar Oct 14 '18 13:10 schnapster

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

reflexin avatar Oct 14 '18 17:10 reflexin

And how do you code that?

YukioKeno avatar Oct 15 '18 04:10 YukioKeno

@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.

BenjaminUrquhart avatar Oct 15 '18 12:10 BenjaminUrquhart

Okay thank you. I'll try that :)

YukioKeno avatar Oct 15 '18 15:10 YukioKeno

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.

zaanposni avatar Apr 18 '20 08:04 zaanposni

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

KaiKikuchi avatar Nov 18 '23 11:11 KaiKikuchi

@KaiKikuchi bots cannot access this endpoint.

MinnDevelopment avatar Nov 18 '23 11:11 MinnDevelopment

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

kohlerpop1 avatar Feb 10 '24 19:02 kohlerpop1

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

freya022 avatar Feb 10 '24 19:02 freya022

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

MinnDevelopment avatar Feb 10 '24 19:02 MinnDevelopment

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.

kohlerpop1 avatar Feb 10 '24 20:02 kohlerpop1