diff --git a/packages/discord.js/src/structures/Channel.js b/packages/discord.js/src/structures/Channel.js index d4061088c..fb889a758 100644 --- a/packages/discord.js/src/structures/Channel.js +++ b/packages/discord.js/src/structures/Channel.js @@ -3,6 +3,7 @@ const { DiscordSnowflake } = require('@sapphire/snowflake'); const { ChannelType, Routes } = require('discord-api-types/v10'); const Base = require('./Base'); +const { ThreadChannelTypes } = require('../util/Constants'); let CategoryChannel; let DMChannel; let NewsChannel; @@ -109,6 +110,14 @@ class Channel extends Base { return this.client.channels.fetch(this.id, { force }); } + /** + * Indicates whether this channel is a {@link ThreadChannel}. + * @returns {boolean} + */ + isThread() { + return ThreadChannelTypes.includes(this.type); + } + /** * Indicates whether this channel is {@link TextBasedChannels text-based}. * @returns {boolean} diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 93b2ea3ce..d74208d8c 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -750,6 +750,7 @@ export abstract class Channel extends Base { public get url(): string; public delete(): Promise; public fetch(force?: boolean): Promise; + public isThread(): this is ThreadChannel; public isTextBased(): this is TextBasedChannel; public isDMBased(): this is PartialGroupDMChannel | DMChannel | PartialDMChannel; public isVoiceBased(): this is VoiceBasedChannel; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 6913113b7..438eee9f5 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -557,7 +557,7 @@ client.on('guildCreate', async g => { channel.send({ components: [row, row2] }); } - if (channel.type === ChannelType.GuildPublicThread) { + if (channel.isThread()) { const fetchedMember = await channel.members.fetch({ member: '12345678' }); expectType(fetchedMember); const fetchedMemberCol = await channel.members.fetch(true);