refactor(channel): remove redundant channel type guards (#8012)

This commit is contained in:
Suneet Tipirneni
2022-06-05 17:29:05 -04:00
committed by GitHub
parent a3287782b5
commit 70c733bb9a
3 changed files with 2 additions and 84 deletions

View File

@@ -3,7 +3,6 @@
const { DiscordSnowflake } = require('@sapphire/snowflake');
const { ChannelType, Routes } = require('discord-api-types/v10');
const Base = require('./Base');
const { ThreadChannelTypes } = require('../util/Constants');
let CategoryChannel;
let DMChannel;
let NewsChannel;
@@ -110,78 +109,6 @@ class Channel extends Base {
return this.client.channels.fetch(this.id, { force });
}
/**
* Indicates whether this channel is a {@link TextChannel}.
* @returns {boolean}
*/
isText() {
return this.type === ChannelType.GuildText;
}
/**
* Indicates whether this channel is a {@link DMChannel}.
* @returns {boolean}
*/
isDM() {
return this.type === ChannelType.DM;
}
/**
* Indicates whether this channel is a {@link VoiceChannel}.
* @returns {boolean}
*/
isVoice() {
return this.type === ChannelType.GuildVoice;
}
/**
* Indicates whether this channel is a {@link PartialGroupDMChannel}.
* @returns {boolean}
*/
isGroupDM() {
return this.type === ChannelType.GroupDM;
}
/**
* Indicates whether this channel is a {@link CategoryChannel}.
* @returns {boolean}
*/
isCategory() {
return this.type === ChannelType.GuildCategory;
}
/**
* Indicates whether this channel is a {@link NewsChannel}.
* @returns {boolean}
*/
isNews() {
return this.type === ChannelType.GuildNews;
}
/**
* Indicates whether this channel is a {@link ThreadChannel}.
* @returns {boolean}
*/
isThread() {
return ThreadChannelTypes.includes(this.type);
}
/**
* Indicates whether this channel is a {@link StageChannel}.
* @returns {boolean}
*/
isStage() {
return this.type === ChannelType.GuildStageVoice;
}
/**
* Indicates whether this channel is a {@link DirectoryChannel}
* @returns {boolean}
*/
isDirectory() {
return this.type === ChannelType.GuildDirectory;
}
/**
* Indicates whether this channel is {@link TextBasedChannels text-based}.
* @returns {boolean}

View File

@@ -748,15 +748,6 @@ export abstract class Channel extends Base {
public get url(): string;
public delete(): Promise<this>;
public fetch(force?: boolean): Promise<this>;
public isText(): this is TextChannel;
public isDM(): this is DMChannel;
public isVoice(): this is VoiceChannel;
public isGroupDM(): this is PartialGroupDMChannel;
public isCategory(): this is CategoryChannel;
public isNews(): this is NewsChannel;
public isThread(): this is ThreadChannel;
public isStage(): this is StageChannel;
public isDirectory(): this is DirectoryChannel;
public isTextBased(): this is TextBasedChannel;
public isDMBased(): this is PartialGroupDMChannel | DMChannel | PartialDMChannel;
public isVoiceBased(): this is VoiceBasedChannel;

View File

@@ -529,7 +529,7 @@ client.on('guildCreate', async g => {
const channel = g.channels.cache.random();
if (!channel) return;
if (channel.isText()) {
if (channel.type === ChannelType.GuildText) {
const row: ActionRowData<MessageActionRowComponentData> = {
type: ComponentType.ActionRow,
components: [
@@ -557,7 +557,7 @@ client.on('guildCreate', async g => {
channel.send({ components: [row, row2] });
}
if (channel.isThread()) {
if (channel.type === ChannelType.GuildPublicThread) {
const fetchedMember = await channel.members.fetch({ member: '12345678' });
expectType<ThreadMember>(fetchedMember);
const fetchedMemberCol = await channel.members.fetch(true);