From b7ed6752ac98e56e79b6fd9fd3a5e47572454d85 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Wed, 30 Jun 2021 20:49:59 +0530 Subject: [PATCH] feat(Channel): add isThread typeguard for better TS support (#5978) --- src/structures/Channel.js | 10 +++++++++- typings/index.d.ts | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/structures/Channel.js b/src/structures/Channel.js index 6c8e759c1..cdae8152a 100644 --- a/src/structures/Channel.js +++ b/src/structures/Channel.js @@ -1,7 +1,7 @@ 'use strict'; const Base = require('./Base'); -const { ChannelTypes } = require('../util/Constants'); +const { ChannelTypes, ThreadChannelTypes } = require('../util/Constants'); const SnowflakeUtil = require('../util/SnowflakeUtil'); /** @@ -110,6 +110,14 @@ class Channel extends Base { return 'messages' in this; } + /** + * Indicates whether this channel is a thread channel. + * @returns {boolean} + */ + isThread() { + return ThreadChannelTypes.includes(this.type); + } + 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 8766ac996..c46cc477d 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -438,6 +438,7 @@ declare module 'discord.js' { public delete(reason?: string): Promise; public fetch(force?: boolean): Promise; public isText(): this is TextChannel | DMChannel | NewsChannel | ThreadChannel; + public isThread(): this is ThreadChannel; public toString(): string; }