mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
refactor: added TextBasedChannels type (#6286)
This commit is contained in:
@@ -14,7 +14,7 @@ module.exports = (client, { d: data }) => {
|
|||||||
* Emitted whenever the pins of a channel are updated. Due to the nature of the WebSocket event,
|
* Emitted whenever the pins of a channel are updated. Due to the nature of the WebSocket event,
|
||||||
* not much information can be provided easily here - you need to manually check the pins yourself.
|
* not much information can be provided easily here - you need to manually check the pins yourself.
|
||||||
* @event Client#channelPinsUpdate
|
* @event Client#channelPinsUpdate
|
||||||
* @param {DMChannel|TextChannel|NewsChannel} channel The channel that the pins update occurred in
|
* @param {TextBasedChannels} channel The channel that the pins update occurred in
|
||||||
* @param {Date} time The time of the pins update
|
* @param {Date} time The time of the pins update
|
||||||
*/
|
*/
|
||||||
client.emit(Events.CHANNEL_PINS_UPDATE, channel, time);
|
client.emit(Events.CHANNEL_PINS_UPDATE, channel, time);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class MessageManager extends CachedManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel that the messages belong to
|
* The channel that the messages belong to
|
||||||
* @type {TextBasedChannel}
|
* @type {TextBasedChannels}
|
||||||
*/
|
*/
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,8 +110,7 @@ class Channel extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether this channel is text-based
|
* Indicates whether this channel is {@link TextBasedChannels text-based}.
|
||||||
* ({@link TextChannel}, {@link DMChannel}, {@link NewsChannel} or {@link ThreadChannel}).
|
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
isText() {
|
isText() {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class CommandInteraction extends Interaction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel this interaction was sent in
|
* The channel this interaction was sent in
|
||||||
* @type {?(TextChannel|NewsChannel|DMChannel)}
|
* @type {?TextBasedChannels}
|
||||||
* @name CommandInteraction#channel
|
* @name CommandInteraction#channel
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ class Interaction extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel this interaction was sent in
|
* The channel this interaction was sent in
|
||||||
* @type {?Channel}
|
* @type {?TextBasedChannels}
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
get channel() {
|
get channel() {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const { InteractionTypes, MessageComponentTypes } = require('../util/Constants')
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {CollectorOptions} InteractionCollectorOptions
|
* @typedef {CollectorOptions} InteractionCollectorOptions
|
||||||
* @property {TextChannel|DMChannel|NewsChannel} [channel] The channel to listen to interactions from
|
* @property {TextBasedChannels} [channel] The channel to listen to interactions from
|
||||||
* @property {MessageComponentType} [componentType] The type of component to listen for
|
* @property {MessageComponentType} [componentType] The type of component to listen for
|
||||||
* @property {Guild} [guild] The guild to listen to interactions from
|
* @property {Guild} [guild] The guild to listen to interactions from
|
||||||
* @property {InteractionType} [interactionType] The type of interaction to listen for
|
* @property {InteractionType} [interactionType] The type of interaction to listen for
|
||||||
@@ -39,7 +39,7 @@ class InteractionCollector extends Collector {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel from which to collect interactions, if provided
|
* The channel from which to collect interactions, if provided
|
||||||
* @type {?(TextChannel|DMChannel|NewsChannel)}
|
* @type {?TextBasedChannels}
|
||||||
*/
|
*/
|
||||||
this.channel = this.message?.channel ?? options.channel ?? null;
|
this.channel = this.message?.channel ?? options.channel ?? null;
|
||||||
|
|
||||||
|
|||||||
@@ -27,14 +27,14 @@ class Message extends Base {
|
|||||||
/**
|
/**
|
||||||
* @param {Client} client The instantiating client
|
* @param {Client} client The instantiating client
|
||||||
* @param {APIMessage} data The data for the message
|
* @param {APIMessage} data The data for the message
|
||||||
* @param {TextChannel|DMChannel|NewsChannel|ThreadChannel} channel The channel the message was sent in
|
* @param {TextBasedChannels} channel The channel the message was sent in
|
||||||
*/
|
*/
|
||||||
constructor(client, data, channel) {
|
constructor(client, data, channel) {
|
||||||
super(client);
|
super(client);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel that the message was sent in
|
* The channel that the message was sent in
|
||||||
* @type {TextChannel|DMChannel|NewsChannel|ThreadChannel}
|
* @type {TextBasedChannels}
|
||||||
*/
|
*/
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const { Events } = require('../util/Constants');
|
|||||||
*/
|
*/
|
||||||
class MessageCollector extends Collector {
|
class MessageCollector extends Collector {
|
||||||
/**
|
/**
|
||||||
* @param {TextChannel|DMChannel} channel The channel
|
* @param {TextBasedChannels} channel The channel
|
||||||
* @param {MessageCollectorOptions} options The options to be applied to this collector
|
* @param {MessageCollectorOptions} options The options to be applied to this collector
|
||||||
* @emits MessageCollector#message
|
* @emits MessageCollector#message
|
||||||
*/
|
*/
|
||||||
@@ -25,7 +25,7 @@ class MessageCollector extends Collector {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel
|
* The channel
|
||||||
* @type {TextBasedChannel}
|
* @type {TextBasedChannels}
|
||||||
*/
|
*/
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const Base = require('./Base');
|
|||||||
*/
|
*/
|
||||||
class Typing extends Base {
|
class Typing extends Base {
|
||||||
/**
|
/**
|
||||||
* @param {TextChannel|DMChannel|NewsChannel|ThreadChannel} channel The channel this typing came from
|
* @param {TextBasedChannels} channel The channel this typing came from
|
||||||
* @param {User} user The user that started typing
|
* @param {User} user The user that started typing
|
||||||
* @param {APITypingStart} data The raw data received
|
* @param {APITypingStart} data The raw data received
|
||||||
*/
|
*/
|
||||||
@@ -17,7 +17,7 @@ class Typing extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel the status is from
|
* The channel the status is from
|
||||||
* @type {TextChannel|DMChannel|NewsChannel|ThreadChannel}
|
* @type {TextBasedChannels}
|
||||||
*/
|
*/
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
|
|
||||||
|
|||||||
@@ -456,6 +456,15 @@ exports.ChannelTypes = createEnum([
|
|||||||
'GUILD_STAGE_VOICE',
|
'GUILD_STAGE_VOICE',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The channels that are text-based.
|
||||||
|
* * DMChannel
|
||||||
|
* * TextChannel
|
||||||
|
* * NewsChannel
|
||||||
|
* * ThreadChannel
|
||||||
|
* @typedef {DMChannel|TextChannel|NewsChannel|ThreadChannel} TextBasedChannels
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The types of channels that are text-based. The available types are:
|
* The types of channels that are text-based. The available types are:
|
||||||
* * DM
|
* * DM
|
||||||
|
|||||||
48
typings/index.d.ts
vendored
48
typings/index.d.ts
vendored
@@ -330,7 +330,7 @@ export class Channel extends Base {
|
|||||||
public type: keyof typeof ChannelTypes;
|
public type: keyof typeof ChannelTypes;
|
||||||
public delete(): Promise<Channel>;
|
public delete(): Promise<Channel>;
|
||||||
public fetch(force?: boolean): Promise<Channel>;
|
public fetch(force?: boolean): Promise<Channel>;
|
||||||
public isText(): this is TextChannel | DMChannel | NewsChannel | ThreadChannel;
|
public isText(): this is TextBasedChannels;
|
||||||
public isThread(): this is ThreadChannel;
|
public isThread(): this is ThreadChannel;
|
||||||
public toString(): ChannelMention;
|
public toString(): ChannelMention;
|
||||||
}
|
}
|
||||||
@@ -472,7 +472,7 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
|
|||||||
export class CommandInteraction extends Interaction {
|
export class CommandInteraction extends Interaction {
|
||||||
public constructor(client: Client, data: RawCommandInteractionData);
|
public constructor(client: Client, data: RawCommandInteractionData);
|
||||||
public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
|
public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
|
||||||
public readonly channel: TextChannel | DMChannel | NewsChannel | PartialDMChannel | ThreadChannel | null;
|
public readonly channel: TextBasedChannels | null;
|
||||||
public channelId: Snowflake;
|
public channelId: Snowflake;
|
||||||
public commandId: Snowflake;
|
public commandId: Snowflake;
|
||||||
public commandName: string;
|
public commandName: string;
|
||||||
@@ -939,7 +939,7 @@ export class Intents extends BitField<IntentsString> {
|
|||||||
export class Interaction extends Base {
|
export class Interaction extends Base {
|
||||||
public constructor(client: Client, data: RawInteractionData);
|
public constructor(client: Client, data: RawInteractionData);
|
||||||
public applicationId: Snowflake;
|
public applicationId: Snowflake;
|
||||||
public readonly channel: Channel | PartialDMChannel | null;
|
public readonly channel: TextBasedChannels | null;
|
||||||
public channelId: Snowflake | null;
|
public channelId: Snowflake | null;
|
||||||
public readonly createdAt: Date;
|
public readonly createdAt: Date;
|
||||||
public readonly createdTimestamp: number;
|
public readonly createdTimestamp: number;
|
||||||
@@ -964,7 +964,7 @@ export class InteractionCollector<T extends Interaction> extends Collector<Snowf
|
|||||||
private _handleChannelDeletion(channel: GuildChannel): void;
|
private _handleChannelDeletion(channel: GuildChannel): void;
|
||||||
private _handleGuildDeletion(guild: Guild): void;
|
private _handleGuildDeletion(guild: Guild): void;
|
||||||
|
|
||||||
public channel: TextChannel | NewsChannel | DMChannel | null;
|
public channel: TextBasedChannels | null;
|
||||||
public componentType: MessageComponentType | null;
|
public componentType: MessageComponentType | null;
|
||||||
public readonly endReason: string | null;
|
public readonly endReason: string | null;
|
||||||
public guild: Guild | null;
|
public guild: Guild | null;
|
||||||
@@ -1048,11 +1048,7 @@ export class LimitedCollection<K, V> extends Collection<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Message extends Base {
|
export class Message extends Base {
|
||||||
public constructor(
|
public constructor(client: Client, data: RawMessageData, channel: TextBasedChannels);
|
||||||
client: Client,
|
|
||||||
data: RawMessageData,
|
|
||||||
channel: TextChannel | DMChannel | NewsChannel | ThreadChannel,
|
|
||||||
);
|
|
||||||
private _patch(data: RawPartialMessageData, partial: true): Message;
|
private _patch(data: RawPartialMessageData, partial: true): Message;
|
||||||
private _patch(data: RawMessageData, partial?: boolean): Message;
|
private _patch(data: RawMessageData, partial?: boolean): Message;
|
||||||
private _update(data: RawPartialMessageData, partial: true): Message;
|
private _update(data: RawPartialMessageData, partial: true): Message;
|
||||||
@@ -1062,7 +1058,7 @@ export class Message extends Base {
|
|||||||
public applicationId: Snowflake | null;
|
public applicationId: Snowflake | null;
|
||||||
public attachments: Collection<Snowflake, MessageAttachment>;
|
public attachments: Collection<Snowflake, MessageAttachment>;
|
||||||
public author: User;
|
public author: User;
|
||||||
public channel: TextChannel | DMChannel | NewsChannel | ThreadChannel;
|
public channel: TextBasedChannels;
|
||||||
public readonly cleanContent: string;
|
public readonly cleanContent: string;
|
||||||
public components: MessageActionRow[];
|
public components: MessageActionRow[];
|
||||||
public content: string;
|
public content: string;
|
||||||
@@ -1175,11 +1171,11 @@ export class MessageButton extends BaseMessageComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class MessageCollector extends Collector<Snowflake, Message> {
|
export class MessageCollector extends Collector<Snowflake, Message> {
|
||||||
public constructor(channel: TextChannel | DMChannel | ThreadChannel, options?: MessageCollectorOptions);
|
public constructor(channel: TextBasedChannels, options?: MessageCollectorOptions);
|
||||||
private _handleChannelDeletion(channel: GuildChannel): void;
|
private _handleChannelDeletion(channel: GuildChannel): void;
|
||||||
private _handleGuildDeletion(guild: Guild): void;
|
private _handleGuildDeletion(guild: Guild): void;
|
||||||
|
|
||||||
public channel: TextChannel | DMChannel | ThreadChannel;
|
public channel: TextBasedChannels;
|
||||||
public readonly endReason: string | null;
|
public readonly endReason: string | null;
|
||||||
public options: MessageCollectorOptions;
|
public options: MessageCollectorOptions;
|
||||||
public received: number;
|
public received: number;
|
||||||
@@ -1190,7 +1186,7 @@ export class MessageCollector extends Collector<Snowflake, Message> {
|
|||||||
|
|
||||||
export class MessageComponentInteraction extends Interaction {
|
export class MessageComponentInteraction extends Interaction {
|
||||||
public constructor(client: Client, data: RawMessageComponentInteractionData);
|
public constructor(client: Client, data: RawMessageComponentInteractionData);
|
||||||
public readonly channel: TextChannel | DMChannel | NewsChannel | PartialDMChannel | ThreadChannel | null;
|
public readonly channel: TextBasedChannels | null;
|
||||||
public readonly component: MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent> | null;
|
public readonly component: MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent> | null;
|
||||||
public componentType: MessageComponentType;
|
public componentType: MessageComponentType;
|
||||||
public customId: string;
|
public customId: string;
|
||||||
@@ -1813,12 +1809,8 @@ export class ThreadMemberFlags extends BitField<ThreadMemberFlagsString> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Typing extends Base {
|
export class Typing extends Base {
|
||||||
public constructor(
|
public constructor(channel: TextBasedChannels, user: PartialUser, data?: RawTypingData);
|
||||||
channel: TextChannel | PartialDMChannel | NewsChannel | ThreadChannel,
|
public channel: TextBasedChannels;
|
||||||
user: PartialUser,
|
|
||||||
data?: RawTypingData,
|
|
||||||
);
|
|
||||||
public channel: TextChannel | PartialDMChannel | NewsChannel | ThreadChannel;
|
|
||||||
public user: PartialUser;
|
public user: PartialUser;
|
||||||
public startedTimestamp: number;
|
public startedTimestamp: number;
|
||||||
public readonly startedAt: Date;
|
public readonly startedAt: Date;
|
||||||
@@ -2499,8 +2491,8 @@ export class GuildMemberRoleManager extends DataManager<Snowflake, Role, RoleRes
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class MessageManager extends CachedManager<Snowflake, Message, MessageResolvable> {
|
export class MessageManager extends CachedManager<Snowflake, Message, MessageResolvable> {
|
||||||
public constructor(channel: TextChannel | DMChannel | ThreadChannel, iterable?: Iterable<RawMessageData>);
|
public constructor(channel: TextBasedChannels, iterable?: Iterable<RawMessageData>);
|
||||||
public channel: TextBasedChannelFields;
|
public channel: TextBasedChannels;
|
||||||
public cache: Collection<Snowflake, Message>;
|
public cache: Collection<Snowflake, Message>;
|
||||||
public crosspost(message: MessageResolvable): Promise<Message>;
|
public crosspost(message: MessageResolvable): Promise<Message>;
|
||||||
public delete(message: MessageResolvable): Promise<void>;
|
public delete(message: MessageResolvable): Promise<void>;
|
||||||
@@ -3039,7 +3031,7 @@ export interface ClientEvents {
|
|||||||
applicationCommandUpdate: [oldCommand: ApplicationCommand | null, newCommand: ApplicationCommand];
|
applicationCommandUpdate: [oldCommand: ApplicationCommand | null, newCommand: ApplicationCommand];
|
||||||
channelCreate: [channel: GuildChannel];
|
channelCreate: [channel: GuildChannel];
|
||||||
channelDelete: [channel: DMChannel | GuildChannel];
|
channelDelete: [channel: DMChannel | GuildChannel];
|
||||||
channelPinsUpdate: [channel: TextChannel | NewsChannel | DMChannel | PartialDMChannel, date: Date];
|
channelPinsUpdate: [channel: TextBasedChannels, date: Date];
|
||||||
channelUpdate: [oldChannel: DMChannel | GuildChannel, newChannel: DMChannel | GuildChannel];
|
channelUpdate: [oldChannel: DMChannel | GuildChannel, newChannel: DMChannel | GuildChannel];
|
||||||
debug: [message: string];
|
debug: [message: string];
|
||||||
warn: [message: string];
|
warn: [message: string];
|
||||||
@@ -3788,7 +3780,7 @@ export interface IntegrationAccount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface InteractionCollectorOptions<T extends Interaction> extends CollectorOptions<[T]> {
|
export interface InteractionCollectorOptions<T extends Interaction> extends CollectorOptions<[T]> {
|
||||||
channel?: TextChannel | DMChannel | NewsChannel | ThreadChannel;
|
channel?: TextBasedChannels;
|
||||||
componentType?: MessageComponentType | MessageComponentTypes;
|
componentType?: MessageComponentType | MessageComponentTypes;
|
||||||
guild?: Guild;
|
guild?: Guild;
|
||||||
interactionType?: InteractionType | InteractionTypes;
|
interactionType?: InteractionType | InteractionTypes;
|
||||||
@@ -4421,13 +4413,9 @@ export interface LimitedCollectionOptions<K, V> {
|
|||||||
sweepInterval?: number;
|
sweepInterval?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TextBasedChannelTypes =
|
export type TextBasedChannels = PartialDMChannel | DMChannel | TextChannel | NewsChannel | ThreadChannel;
|
||||||
| 'DM'
|
|
||||||
| 'GUILD_TEXT'
|
export type TextBasedChannelTypes = TextBasedChannels['type'];
|
||||||
| 'GUILD_NEWS'
|
|
||||||
| 'GUILD_NEWS_THREAD'
|
|
||||||
| 'GUILD_PUBLIC_THREAD'
|
|
||||||
| 'GUILD_PRIVATE_THREAD';
|
|
||||||
|
|
||||||
export type TextChannelResolvable = Snowflake | TextChannel;
|
export type TextChannelResolvable = Snowflake | TextChannel;
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import {
|
|||||||
StageChannel,
|
StageChannel,
|
||||||
StoreChannel,
|
StoreChannel,
|
||||||
TextBasedChannelFields,
|
TextBasedChannelFields,
|
||||||
|
TextBasedChannels,
|
||||||
TextChannel,
|
TextChannel,
|
||||||
ThreadChannel,
|
ThreadChannel,
|
||||||
Typing,
|
Typing,
|
||||||
@@ -662,7 +663,7 @@ declare const typing: Typing;
|
|||||||
assertType<PartialUser>(typing.user);
|
assertType<PartialUser>(typing.user);
|
||||||
if (typing.user.partial) assertType<null>(typing.user.username);
|
if (typing.user.partial) assertType<null>(typing.user.username);
|
||||||
|
|
||||||
assertType<TextChannel | PartialDMChannel | NewsChannel | ThreadChannel>(typing.channel);
|
assertType<TextBasedChannels>(typing.channel);
|
||||||
if (typing.channel.partial) assertType<undefined>(typing.channel.lastMessageId);
|
if (typing.channel.partial) assertType<undefined>(typing.channel.lastMessageId);
|
||||||
|
|
||||||
assertType<GuildMember | null>(typing.member);
|
assertType<GuildMember | null>(typing.member);
|
||||||
|
|||||||
Reference in New Issue
Block a user