fix: readd isThread type guard (#8019)

This commit is contained in:
Parbez
2022-06-06 17:54:03 +05:30
committed by GitHub
parent e1176faa27
commit f8ed71bfca
3 changed files with 11 additions and 1 deletions

View File

@@ -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}

View File

@@ -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;

View File

@@ -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);