Skip to content

Commit

Permalink
feat(Channel): add isText() type guard (#4745)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaporoxx committed Aug 31, 2020
1 parent 3141f7c commit b0ab37d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/structures/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ class Channel extends Base {
return this.client.channels.fetch(this.id, true, force);
}

/**
* Indicates whether this channel is text-based.
* @returns {boolean}
*/
isText() {
return 'messages' in this;
}

static create(client, data, guild) {
const Structures = require('../util/Structures');
let channel;
Expand Down
2 changes: 2 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ declare module 'discord.js' {
public type: keyof typeof ChannelType;
public delete(reason?: string): Promise<Channel>;
public fetch(force?: boolean): Promise<Channel>;
public isText(): this is TextChannel | DMChannel | NewsChannel;
public toString(): string;
}

Expand Down Expand Up @@ -826,6 +827,7 @@ declare module 'discord.js' {
options: PermissionOverwriteOption,
reason?: string,
): Promise<this>;
public isText(): this is TextChannel | NewsChannel;
}

export class GuildEmoji extends BaseGuildEmoji {
Expand Down

0 comments on commit b0ab37d

Please sign in to comment.