JDA
JDA copied to clipboard
Get invite code on member Join
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.
This information is not available from the Discord API...yet.
See https://github.com/discordapp/discord-api-docs/issues/448
I wrote a bot to do this with an algorithm, so it's still possible to create.
And how do you code that?
@YukioKeno
- Store how many times all invites have been used
- When a user joins, see which invite has a use incremented by 1
- That's probably the invite they used.
Okay thank you. I'll try that :)
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
.
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 bots cannot access this endpoint.
This is now possible to retrieve via the API.
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
Good chances it won't be added until it's documented
This endpoint is still unfinished and not intended to be used in production. JDA does not support unfinished API features.
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.