Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type guard for sendable text-based channels #10482

Merged
merged 6 commits into from
Sep 6, 2024
Merged

Conversation

vladfrangu
Copy link
Member

Please describe the changes this PR makes and why it should be merged:

Adds in BaseChannel#isSendable, which is a mix of isTextBased() and checking if you can actually send messages in the channel. This way, we can have the correct types for interaction.channel, and you can assert whether you got the interaction from a Group DM Channel or not

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
  • This PR changes the library's interface (methods or parameters added)

Copy link

vercel bot commented Sep 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Visit Preview Sep 6, 2024 7:15am
discord-js-guide ⬜️ Ignored (Inspect) Visit Preview Sep 6, 2024 7:15am

@imnaiyar
Copy link
Contributor

imnaiyar commented Sep 4, 2024

IG this (and the JSDoc) can also be updated to include PartialGroupDMChannel since it's considered text-based now

/**
* The channels that are text-based.
* * {@link DMChannel}
* * {@link GuildTextBasedChannel}
* @typedef {DMChannel|GuildTextBasedChannel} TextBasedChannels
*/
/**
* Data that resolves to give a text-based channel. This can be:
* * A {@link TextBasedChannel}
* * A {@link Snowflake}
* @typedef {TextBasedChannels|Snowflake} TextBasedChannelsResolvable
*/
/**
* The types of channels that are text-based. The available types are:
* * {@link ChannelType.DM}
* * {@link ChannelType.GuildText}
* * {@link ChannelType.GuildAnnouncement}
* * {@link ChannelType.AnnouncementThread}
* * {@link ChannelType.PublicThread}
* * {@link ChannelType.PrivateThread}
* * {@link ChannelType.GuildVoice}
* * {@link ChannelType.GuildStageVoice}
* @typedef {ChannelType[]} TextBasedChannelTypes
*/
exports.TextBasedChannelTypes = [...exports.GuildTextBasedChannelTypes, ChannelType.DM];

packages/discord.js/typings/index.d.ts Outdated Show resolved Hide resolved
Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com>
@Jiralite Jiralite changed the title fix: type-guard for sendable text-based channels fix: type guard for sendable text-based channels Sep 4, 2024
@kodiakhq kodiakhq bot merged commit dea6840 into main Sep 6, 2024
8 checks passed
@kodiakhq kodiakhq bot deleted the fix/issendable branch September 6, 2024 07:16
nyapat pushed a commit to nyapat/discord.js that referenced this pull request Oct 4, 2024
* fix: type-guard for sendable text-based channels

* chore: suggested change

* Update packages/discord.js/typings/index.test-d.ts

Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com>

* fix: make isSendable strictly check for `.send`

* fix: tests

---------

Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com>
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants