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 isThread typeguard for better TS support #5978

Merged
merged 2 commits into from Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/structures/Channel.js
@@ -1,7 +1,7 @@
'use strict';

const Base = require('./Base');
const { ChannelTypes } = require('../util/Constants');
const { ChannelTypes, ThreadChannelTypes } = require('../util/Constants');
const SnowflakeUtil = require('../util/SnowflakeUtil');

/**
Expand Down Expand Up @@ -110,6 +110,14 @@ class Channel extends Base {
return 'messages' in this;
}

/**
* Indicates whether this channel is a thread channel.
* @returns {boolean}
*/
isThread() {
return ThreadChannelTypes.includes(this.type);
}

static create(client, data, guild) {
const Structures = require('../util/Structures');
let channel;
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -438,6 +438,7 @@ declare module 'discord.js' {
public delete(reason?: string): Promise<Channel>;
public fetch(force?: boolean): Promise<Channel>;
public isText(): this is TextChannel | DMChannel | NewsChannel | ThreadChannel;
public isThread(): this is ThreadChannel;
public toString(): string;
}

Expand Down