From b0ab37ddc0614910e032ccf423816e106c3804e5 Mon Sep 17 00:00:00 2001 From: Jan <66554238+Vaporox@users.noreply.github.com> Date: Mon, 31 Aug 2020 09:59:17 +0200 Subject: [PATCH] feat(Channel): add isText() type guard (#4745) --- src/structures/Channel.js | 8 ++++++++ typings/index.d.ts | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/structures/Channel.js b/src/structures/Channel.js index 37913046f..52867c645 100644 --- a/src/structures/Channel.js +++ b/src/structures/Channel.js @@ -97,6 +97,14 @@ class Channel extends Base { return this.client.channels.fetch(this.id, true, force); } + /** + * Indicates whether this channel is text-based. + * @returns {boolean} + */ + isText() { + return 'messages' in this; + } + static create(client, data, guild) { const Structures = require('../util/Structures'); let channel; diff --git a/typings/index.d.ts b/typings/index.d.ts index 783238b18..b0dddb5cd 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -187,6 +187,7 @@ declare module 'discord.js' { public type: keyof typeof ChannelType; public delete(reason?: string): Promise; public fetch(force?: boolean): Promise; + public isText(): this is TextChannel | DMChannel | NewsChannel; public toString(): string; } @@ -826,6 +827,7 @@ declare module 'discord.js' { options: PermissionOverwriteOption, reason?: string, ): Promise; + public isText(): this is TextChannel | NewsChannel; } export class GuildEmoji extends BaseGuildEmoji {