Skip to content

Commit

Permalink
feat(channel): add isDMBased typeguard (#7362)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImRodry authored Jan 30, 2022
1 parent 567db60 commit 388f535
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/discord.js/src/structures/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ class Channel extends Base {
return 'messages' in this;
}

/**
* Indicates whether this channel is DM-based (either a {@link DMChannel} or a {@link GroupDMChannel}).
* @returns {boolean}
*/
isDMBased() {
return [ChannelType.DM, ChannelType.GroupDM].includes(this.type);
}

/**
* Indicates whether this channel is {@link BaseGuildVoiceChannel voice-based}.
* @returns {boolean}
Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ export abstract class Channel extends Base {
public isThread(): this is ThreadChannel;
public isStage(): this is StageChannel;
public isTextBased(): this is TextBasedChannel;
public isDMBased(): this is PartialGroupDMChannel | DMChannel;
public isVoiceBased(): this is VoiceBasedChannel;
public toString(): ChannelMention;
}
Expand Down Expand Up @@ -1688,6 +1689,7 @@ export class OAuth2Guild extends BaseGuild {

export class PartialGroupDMChannel extends Channel {
private constructor(client: Client, data: RawPartialGroupDMChannelData);
public type: ChannelType.GroupDM;
public name: string | null;
public icon: string | null;
public recipients: PartialRecipient[];
Expand Down

0 comments on commit 388f535

Please sign in to comment.