From 388f53550cca7ded7350a050fda03c36e4c1fdf7 Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Sun, 30 Jan 2022 11:57:03 +0000 Subject: [PATCH] feat(channel): add isDMBased typeguard (#7362) --- packages/discord.js/src/structures/Channel.js | 8 ++++++++ packages/discord.js/typings/index.d.ts | 2 ++ 2 files changed, 10 insertions(+) diff --git a/packages/discord.js/src/structures/Channel.js b/packages/discord.js/src/structures/Channel.js index bba09cdf6..18060d45e 100644 --- a/packages/discord.js/src/structures/Channel.js +++ b/packages/discord.js/src/structures/Channel.js @@ -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} diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 56db640aa..a577fd6a6 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -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; } @@ -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[];