mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor(channel): remove redundant channel type guards (#8012)
This commit is contained in:
@@ -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}
|
||||
|
||||
9
packages/discord.js/typings/index.d.ts
vendored
9
packages/discord.js/typings/index.d.ts
vendored
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user