Skip to content

Commit

Permalink
fix: readd isThread type guard (#8019)
Browse files Browse the repository at this point in the history
  • Loading branch information
imranbarbhuiya committed Jun 6, 2022
1 parent e1176fa commit f8ed71b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/discord.js/src/structures/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ export abstract class Channel extends Base {
public get url(): string;
public delete(): Promise<this>;
public fetch(force?: boolean): Promise<this>;
public isThread(): this is ThreadChannel;
public isTextBased(): this is TextBasedChannel;
public isDMBased(): this is PartialGroupDMChannel | DMChannel | PartialDMChannel;
public isVoiceBased(): this is VoiceBasedChannel;
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThreadMember>(fetchedMember);
const fetchedMemberCol = await channel.members.fetch(true);
Expand Down

0 comments on commit f8ed71b

Please sign in to comment.