Skip to content

Commit

Permalink
feat(Channel): add isThread typeguard for better TS support (#5978)
Browse files Browse the repository at this point in the history
  • Loading branch information
iShibi authored Jun 30, 2021
1 parent 788d58e commit b7ed675
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/structures/Channel.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit b7ed675

Please sign in to comment.