Skip to content

Commit b0ab37d

Browse files
authored
feat(Channel): add isText() type guard (#4745)
1 parent 3141f7c commit b0ab37d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/structures/Channel.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ class Channel extends Base {
9797
return this.client.channels.fetch(this.id, true, force);
9898
}
9999

100+
/**
101+
* Indicates whether this channel is text-based.
102+
* @returns {boolean}
103+
*/
104+
isText() {
105+
return 'messages' in this;
106+
}
107+
100108
static create(client, data, guild) {
101109
const Structures = require('../util/Structures');
102110
let channel;

typings/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ declare module 'discord.js' {
187187
public type: keyof typeof ChannelType;
188188
public delete(reason?: string): Promise<Channel>;
189189
public fetch(force?: boolean): Promise<Channel>;
190+
public isText(): this is TextChannel | DMChannel | NewsChannel;
190191
public toString(): string;
191192
}
192193

@@ -826,6 +827,7 @@ declare module 'discord.js' {
826827
options: PermissionOverwriteOption,
827828
reason?: string,
828829
): Promise<this>;
830+
public isText(): this is TextChannel | NewsChannel;
829831
}
830832

831833
export class GuildEmoji extends BaseGuildEmoji {

0 commit comments

Comments
 (0)