Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Channel): add isText() type guard #4745

Merged
merged 3 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ['text', 'dm', 'news'].includes(this.type);
vaporoxx marked this conversation as resolved.
Show resolved Hide resolved
}

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 @@ -160,6 +160,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 @@ -800,6 +801,7 @@ declare module 'discord.js' {
options: PermissionOverwriteOption,
reason?: string,
): Promise<this>;
public isText(): this is TextChannel | NewsChannel;
}

export class GuildEmoji extends BaseGuildEmoji {
Expand Down