Skip to content

types(CommandInteractionOptionResolver): getChannels type fix#11380

Draft
Pavel-Boyazov wants to merge 1 commit intodiscordjs:mainfrom
Pavel-Boyazov:getChannels-type-fix
Draft

types(CommandInteractionOptionResolver): getChannels type fix#11380
Pavel-Boyazov wants to merge 1 commit intodiscordjs:mainfrom
Pavel-Boyazov:getChannels-type-fix

Conversation

@Pavel-Boyazov
Copy link
Contributor

Please describe the changes this PR makes and why it should be merged:
getChannels can't return channel types that not in allowed

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

Why no description template?..

@vercel
Copy link

vercel bot commented Jan 13, 2026

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

2 Skipped Deployments
Project Deployment Review Updated (UTC)
discord-js Skipped Skipped Jan 13, 2026 9:49pm
discord-js-guide Skipped Skipped Jan 13, 2026 9:49pm

@vercel vercel bot temporarily deployed to Preview – discord-js-guide January 13, 2026 21:49 Inactive
@coderabbitai
Copy link

coderabbitai bot commented Jan 13, 2026

📝 Walkthrough

Walkthrough

Updated the generic type constraint for two overloads of CommandInteractionOptionResolver.getChannel method from ChannelType to ApplicationCommandOptionAllowedChannelType in the TypeScript type definitions. No runtime behavior changes; adjusts the type hierarchy for channel type parameter validation.

Changes

Cohort / File(s) Change Summary
Type Definition Updates
packages/discord.js/typings/index.d.ts
Updated getChannel method overloads (2×): Generic type constraint widened from ChannelType to ApplicationCommandOptionAllowedChannelType for both overloads and their default type parameters

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing the type constraints for getChannel method in CommandInteractionOptionResolver to restrict it to allowed channel types.
Description check ✅ Passed The description is related to the changeset, explaining that getChannels cannot return channel types that are not in the allowed set, which aligns with the type constraint changes made.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ccae83 and d2d1d57.

📒 Files selected for processing (1)
  • packages/discord.js/typings/index.d.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/discord.js/typings/index.d.ts (1)
packages/builders/src/interactions/commands/chatInput/mixins/ApplicationCommandOptionChannelTypesMixin.ts (1)
  • ApplicationCommandOptionAllowedChannelType (20-20)
⏰ 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 (3)
packages/discord.js/typings/index.d.ts (3)

1193-1206: Good narrowing of getChannel() generic from ChannelTypeApplicationCommandOptionAllowedChannelType.
This prevents callers from passing invalid channelTypes (e.g., DM-related types) and makes the default return type better reflect what slash-command channel options can actually return. The thread special-casing in the Extract<> still looks coherent.

Optional: add a lightweight dts test to lock the behavior
// Expect error: DM is not an allowed application-command channel option type
interaction.options.getChannel('c', true, [ChannelType.DM]);

// Expect OK: allowed guild types
interaction.options.getChannel('c', true, [ChannelType.GuildText, ChannelType.GuildVoice]);

1213-1226: Overload parity maintained (nullable variant matches the required-true variant).
No further concerns, assuming the allowed-type union covers all channel types that can be resolved for command channel options.


5-5: The import is correct and properly sourced. ApplicationCommandOptionAllowedChannelType is defined in @discordjs/builders as a union type derived from the ChannelType enum in discord-api-types/v10—Discord's canonical type source. It includes the following allowed channel types: GuildText, GuildVoice, GuildCategory, GuildAnnouncement, AnnouncementThread, PublicThread, PrivateThread, GuildStageVoice, GuildForum, and GuildMedia. This aligns with Discord's API specification for ApplicationCommandOptionType.Channel.

The getChannel method (lines 1193–1220) correctly constrains its generic type parameter to ApplicationCommandOptionAllowedChannelType, enabling type-safe filtering of results by channel type.


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 and usage tips.

@Qjuh
Copy link
Member

Qjuh commented Jan 14, 2026

Need to fix tests, but other than that LGTM

@Pavel-Boyazov
Copy link
Contributor Author

Pavel-Boyazov commented Jan 15, 2026

Need to fix tests, but other than that LGTM

What's the best way to proceed? I've realized that for this change to work correctly, we need to modify type APIInteractionDataResolvedChannel in the discord-api-types. This type uses all channel types, but we need only option allowed.

  1. Should I open an PR in the discord-api-types repository and link to it here?
  2. Or would it be better to implement a temporary workaround within this PR to avoid blocking the changes?
  3. Or perhaps I'm missing something, and you have a better approach?

Please let me know your preference.

@Pavel-Boyazov
Copy link
Contributor Author

Pavel-Boyazov commented Jan 15, 2026

If we choose the first option, we need the @discordjs/builders dependency in discord-api-types repo, but discord-api-types has no dependencies. Should I copy ApplicationCommandOptionAllowedChannelType or add dependency and import it?

@almeidx
Copy link
Member

almeidx commented Jan 15, 2026

The APIInteractionDataResolvedChannel type should be fixed in discord-api-types, and the ApplicationCommandOptionAllowedChannelType type should live in discord-api-types as well (which builders will consume instead once upgraded).
discord-api-types shouldn't have any dependency on @discordjs/builders.

@Pavel-Boyazov
Copy link
Contributor Author

Pavel-Boyazov commented Jan 15, 2026

3 PRs. Sounds like fun 😅 Okay, got it
UPD: Oops. 2. Forgot for monorepo

@Pavel-Boyazov Pavel-Boyazov marked this pull request as draft January 15, 2026 20:37
@Pavel-Boyazov
Copy link
Contributor Author

Pavel-Boyazov commented Jan 15, 2026

Need to fix tests, but other than that LGTM

Update. Discord allows to choose DM and DMGroup channels in DMs. Can anyone checks for GuildDirectory channel type?
DMs usage shocked me, maybe and directory can be used in specific cases?

I don't have servers with directory to check this and don't know how to find them

@Pavel-Boyazov
Copy link
Contributor Author

@Qjuh @almeidx

@Qjuh
Copy link
Member

Qjuh commented Jan 16, 2026

Bots aren't able to join servers with directory channnels. So this is irrelevant. Judging by your findings and the API documentation I'd say discord-api-types are correct and so were the typings. But the ApplicationCommandOptionAllowedChannelType type isn't.

@Qjuh
Copy link
Member

Qjuh commented Feb 16, 2026

Will you turn this PR into a fix for ApplicationCommandOptionAllowedChannelType in @discordjs/builders or should this be closed and the fix will be a new PR?

@Qjuh Qjuh self-requested a review February 16, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants