Skip to content

feat(invite): new endpoints and target users file and roles - #11392

Open
imnaiyar wants to merge 21 commits into
discordjs:mainfrom
imnaiyar:feat/new-invites
Open

feat(invite): new endpoints and target users file and roles#11392
imnaiyar wants to merge 21 commits into
discordjs:mainfrom
imnaiyar:feat/new-invites

Conversation

@imnaiyar

@imnaiyar imnaiyar commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

@vercel

vercel Bot commented Jan 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
discord-js Skipped Skipped Aug 11, 2026 7:32pm
discord-js-guide Skipped Skipped Aug 11, 2026 7:32pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide January 22, 2026 18:47 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js January 22, 2026 18:47 Inactive
@coderabbitai

coderabbitai Bot commented Jan 22, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR introduces target users management for Guild Invites. It adds new parameters to invite creation (roles, targetUsersFile), implements methods to fetch and update target users via FormData, retrieves job status for async user processing, and adds corresponding TypeScript definitions across multiple files.

Changes

Cohort / File(s) Summary
Core Invite Manager Implementation
packages/discord.js/src/managers/GuildInviteManager.js
Extended create() method with roles and targetUsersFile parameters. Added three public methods (fetchTargetUsers, updateTargetUsers, fetchTargetUsersJobStatus) to manage target users. Introduced private _createInviteFormData() helper to construct FormData payloads for file uploads. Conditional FormData/JSON body handling based on file presence.
Invite Structure & Delegation
packages/discord.js/src/structures/GuildInvite.js
Added roles property (Collection or null) populated during _patch(). Introduced three convenience methods that delegate to GuildInviteManager equivalents. Updated toJSON() to include roles in serialized output.
Type Definitions
packages/discord.js/typings/index.d.ts
Imported InviteTargetUsersJobStatus from discord-api-types. Extended GuildInvite with roles property and new methods. Extended GuildInviteManager with target users management methods. Expanded InviteCreateOptions with roles and targetUsersFile fields. Added new TargetUsersJobStatusForInvite interface with status tracking fields.
Documentation & JSDoc
packages/discord.js/src/structures/BaseGuildTextChannel.js, packages/discord.js/src/util/APITypes.js
Updated InviteCreateOptions typedef with targetUsersFile and roles properties. Added external documentation block for InviteTargetUsersJobStatus API type.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GuildInvite
    participant GuildInviteManager
    participant Discord API

    Client->>GuildInvite: updateTargetUsers(targetUsersFile)
    GuildInvite->>GuildInviteManager: updateTargetUsers(code, targetUsersFile)
    GuildInviteManager->>GuildInviteManager: _createInviteFormData(targetUsersFile)
    Note over GuildInviteManager: Resolve file/array to CSV<br/>Build FormData payload
    GuildInviteManager->>Discord API: POST with FormData
    Discord API-->>GuildInviteManager: Job queued
    GuildInviteManager-->>GuildInvite: Promise<unknown>
    GuildInvite-->>Client: Result

    Client->>GuildInvite: fetchTargetUsersJobStatus()
    GuildInvite->>GuildInviteManager: fetchTargetUsersJobStatus(code)
    GuildInviteManager->>Discord API: GET job status
    Discord API-->>GuildInviteManager: Status object
    GuildInviteManager-->>Client: TargetUsersJobStatusForInvite
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: adding new invite endpoints and support for target users file and roles management.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The description references the dependent API-types change and issue tied to these invite endpoint updates.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Fix all issues with AI agents
In `@packages/discord.js/src/managers/GuildInviteManager.js`:
- Around line 266-313: The JSDoc return types are wrong for the async methods:
change fetchTargetUsers' `@returns` from {Buffer} to {Promise<Buffer>}, change
fetchTargetUsersJobStatus' `@returns` from {TargetUsersJobStatusForInvite[]}
(array) to {Promise<TargetUsersJobStatusForInvite>}, and ensure
updateTargetUsers (async) documents its return as {Promise<unknown>} if kept;
update the JSDoc comments above the functions fetchTargetUsers,
updateTargetUsers, and fetchTargetUsersJobStatus to reflect these Promise<>
return types.
- Around line 232-240: The current construction of options for invite creation
(in GuildInviteManager.js where options.role_ids is built from roles?.map(role
=> this.guild.roles.resolveId(role))) can include null entries which cause API
400s; update the logic that builds role_ids to either filter out falsy/null
resolved IDs (e.g., roles?.map(...).filter(Boolean)) or validate/throw if any
role fails to resolve so you never send nulls to the API, keeping references to
role_ids and this.guild.roles.resolveId in your change.
- Around line 322-334: In _createInviteFormData, filter out unresolved user IDs
returned by this.client.users.resolveId when handling an array targetUsersFile
so the CSV doesn't contain "null" entries; replace the current map(...).join
with a map -> filter(Boolean) -> join('\n') pipeline and if the resulting
usersCsv is empty either throw a clear error or handle it consistently (e.g.,
reject the request) before appending the Blob and payload_json to the FormData.

In `@packages/discord.js/src/structures/GuildInvite.js`:
- Around line 222-228: The JSDoc for the "Update target users of this invite"
method in GuildInvite.js has a typo in the `@returns` type — change
"Promes<unknown>" to "Promise<unknown>" in the JSDoc block above the
update-target-users method (the JSDoc attached to the GuildInvite update
function) so the return type is correctly documented.
- Around line 184-191: The roles Collection for GuildInvite is being constructed
with each Role instantiated from the whole invite payload (new Role(this.client,
data, this.guild)), causing mismatched fields; change the constructor to use the
individual role payload (use the loop variable, e.g., role) so each entry is new
Role(this.client, role, this.guild) and the Collection key remains consistent
with role.id in the roles assignment inside the GuildInvite class.
📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 838cd2d and f39589b.

📒 Files selected for processing (5)
  • packages/discord.js/src/managers/GuildInviteManager.js
  • packages/discord.js/src/structures/BaseGuildTextChannel.js
  • packages/discord.js/src/structures/GuildInvite.js
  • packages/discord.js/src/util/APITypes.js
  • packages/discord.js/typings/index.d.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/discord.js/src/structures/GuildInvite.js (2)
packages/discord.js/src/managers/GuildInviteManager.js (7)
  • require (3-3)
  • require (4-4)
  • require (5-5)
  • require (6-6)
  • require (7-7)
  • require (8-8)
  • require (9-9)
packages/discord.js/typings/index.d.ts (2)
  • Collection (1084-1084)
  • Role (2965-3005)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Tests
🔇 Additional comments (8)
packages/discord.js/src/util/APITypes.js (1)

522-526: Doc addition looks good.
Clear external reference for the new enum.

packages/discord.js/src/structures/BaseGuildTextChannel.js (1)

164-166: InviteCreateOptions docs are clear and consistent.
No issues found.

packages/discord.js/src/structures/GuildInvite.js (2)

3-3: Required imports added for new roles support.

Also applies to: 11-11


261-261: Serialization update is appropriate.

packages/discord.js/typings/index.d.ts (2)

2064-2077: Type additions align with the new invite target-users API.

The roles/targetUsersFile options, job-status type, and manager method signatures are coherent.

Also applies to: 4521-4543, 6605-6610


163-166: Verify that discord-api-types 0.38.36 exports InviteTargetUsersJobStatus.

The import is present in the typings file and the type is actively used (line 165, also used in a type definition with status: InviteTargetUsersJobStatus). However, web searches did not confirm that InviteTargetUsersJobStatus is available in discord-api-types v0.38.36. The package.json specifies ^0.38.36, but the symbol's availability in this version could not be verified from available documentation or changelogs. Confirm the dependency version includes this export, or bump to the version that includes the required symbol.

packages/discord.js/src/managers/GuildInviteManager.js (2)

3-8: Import updates look good.


107-117: Typedef shape is clear.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread packages/discord.js/src/managers/GuildInviteManager.js
Comment thread packages/discord.js/src/managers/GuildInviteManager.js Outdated
Comment thread packages/discord.js/src/managers/GuildInviteManager.js Outdated
Comment thread packages/discord.js/src/structures/GuildInvite.js Outdated
Comment thread packages/discord.js/src/structures/GuildInvite.js
@vercel
vercel Bot temporarily deployed to Preview – discord-js January 22, 2026 19:26 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide January 22, 2026 19:26 Inactive
@Jiralite
Jiralite marked this pull request as draft January 22, 2026 19:28
@vercel
vercel Bot temporarily deployed to Preview – discord-js February 24, 2026 17:21 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide February 24, 2026 17:21 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js July 12, 2026 16:10 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide July 12, 2026 16:10 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide July 13, 2026 05:17 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js July 13, 2026 05:17 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide July 17, 2026 05:28 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js July 17, 2026 05:28 Inactive
@imnaiyar
imnaiyar marked this pull request as ready for review July 17, 2026 05:37
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide July 17, 2026 15:07 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js July 17, 2026 15:07 Inactive
Comment thread packages/discord.js/typings/index.d.ts Outdated
Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com>
@vercel
vercel Bot temporarily deployed to Preview – discord-js August 2, 2026 14:44 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide August 2, 2026 14:44 Inactive
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.06%. Comparing base (4b3f1c1) to head (83667c5).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/core/src/api/invite.ts 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11392      +/-   ##
==========================================
- Coverage   32.07%   32.06%   -0.01%     
==========================================
  Files         390      390              
  Lines       14100    14102       +2     
  Branches     1113     1113              
==========================================
  Hits         4522     4522              
- Misses       9440     9442       +2     
  Partials      138      138              
Flag Coverage Δ
brokers 11.56% <ø> (ø)
core 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread packages/discord.js/src/managers/GuildInviteManager.js Outdated
@vercel
vercel Bot temporarily deployed to Preview – discord-js August 2, 2026 18:27 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide August 2, 2026 18:27 Inactive
@imnaiyar
imnaiyar requested a review from Qjuh August 2, 2026 18:28
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide August 2, 2026 19:00 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js August 2, 2026 19:00 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js August 2, 2026 19:20 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide August 2, 2026 19:20 Inactive
Comment thread packages/core/src/api/channel.ts
Comment thread packages/discord.js/typings/index.d.ts
Comment thread packages/discord.js/src/util/DataResolver.js Outdated
Comment thread packages/discord.js/src/structures/InviteRole.js Outdated
Comment thread packages/discord.js/typings/index.d.ts Outdated
Comment thread packages/core/src/api/invite.ts
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
@vercel
vercel Bot temporarily deployed to Preview – discord-js August 6, 2026 17:14 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide August 6, 2026 17:14 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide August 7, 2026 19:33 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js August 7, 2026 19:33 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js August 7, 2026 21:19 Inactive
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide August 7, 2026 21:19 Inactive
Comment thread packages/discord.js/typings/index.d.ts
@vercel
vercel Bot temporarily deployed to Preview – discord-js-guide August 11, 2026 19:31 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Review in Progress

Development

Successfully merging this pull request may close these issues.

support role_ids on GuildInviteManager#create (Community Invites auto-role assignment)

4 participants