From e24970e3c3d24f71ba711e59666cd8a49a33e33b Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> Date: Fri, 24 Jun 2022 04:42:50 -0400 Subject: [PATCH] refactor: Use `Base` prefix for channel and interaction base classes (#8099) --- packages/discord.js/src/client/Client.js | 2 +- .../src/client/actions/InteractionCreate.js | 2 +- packages/discord.js/src/index.js | 4 +- .../discord.js/src/managers/ChannelManager.js | 12 +-- .../src/structures/AutocompleteInteraction.js | 6 +- .../structures/{Channel.js => BaseChannel.js} | 8 +- .../{Interaction.js => BaseInteraction.js} | 7 +- .../src/structures/CommandInteraction.js | 8 +- .../discord.js/src/structures/DMChannel.js | 6 +- .../src/structures/DirectoryChannel.js | 6 +- .../src/structures/GuildAuditLogsEntry.js | 2 +- .../discord.js/src/structures/GuildChannel.js | 6 +- .../src/structures/InteractionCollector.js | 8 +- .../src/structures/InteractionResponse.js | 4 +- packages/discord.js/src/structures/Invite.js | 2 +- .../structures/MessageComponentInteraction.js | 6 +- .../src/structures/MessageMentions.js | 4 +- .../src/structures/MessagePayload.js | 12 ++- .../src/structures/ModalSubmitInteraction.js | 4 +- .../src/structures/PartialGroupDMChannel.js | 6 +- .../src/structures/ThreadChannel.js | 6 +- .../interfaces/InteractionResponses.js | 4 +- packages/discord.js/src/util/Util.js | 6 +- packages/discord.js/typings/index.d.ts | 96 +++++++++++-------- packages/discord.js/typings/index.test-d.ts | 13 +-- 25 files changed, 128 insertions(+), 112 deletions(-) rename packages/discord.js/src/structures/{Channel.js => BaseChannel.js} (95%) rename packages/discord.js/src/structures/{Interaction.js => BaseInteraction.js} (98%) diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index ff07ba3d8..010c7d517 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -118,7 +118,7 @@ class Client extends BaseClient { this.guilds = new GuildManager(this); /** - * All of the {@link Channel}s that the client is currently handling, mapped by their ids - + * All of the {@link BaseChannel}s that the client is currently handling, mapped by their ids - * as long as sharding isn't being used, this will be *every* channel in *every* guild the bot * is a member of. Note that DM channels will not be initially cached, and thus not be present * in the Manager without their explicit fetching or use. diff --git a/packages/discord.js/src/client/actions/InteractionCreate.js b/packages/discord.js/src/client/actions/InteractionCreate.js index a26478142..9d2b12dce 100644 --- a/packages/discord.js/src/client/actions/InteractionCreate.js +++ b/packages/discord.js/src/client/actions/InteractionCreate.js @@ -76,7 +76,7 @@ class InteractionCreateAction extends Action { /** * Emitted when an interaction is created. * @event Client#interactionCreate - * @param {Interaction} interaction The interaction which was created + * @param {BaseInteraction} interaction The interaction which was created */ client.emit(Events.InteractionCreate, interaction); } diff --git a/packages/discord.js/src/index.js b/packages/discord.js/src/index.js index cec87f861..e4befba11 100644 --- a/packages/discord.js/src/index.js +++ b/packages/discord.js/src/index.js @@ -94,7 +94,7 @@ exports.ButtonBuilder = require('./structures/ButtonBuilder'); exports.ButtonComponent = require('./structures/ButtonComponent'); exports.ButtonInteraction = require('./structures/ButtonInteraction'); exports.CategoryChannel = require('./structures/CategoryChannel'); -exports.Channel = require('./structures/Channel').Channel; +exports.BaseChannel = require('./structures/BaseChannel').BaseChannel; exports.ChatInputCommandInteraction = require('./structures/ChatInputCommandInteraction'); exports.ClientApplication = require('./structures/ClientApplication'); exports.ClientPresence = require('./structures/ClientPresence'); @@ -121,7 +121,7 @@ exports.GuildScheduledEvent = require('./structures/GuildScheduledEvent').GuildS exports.GuildTemplate = require('./structures/GuildTemplate'); exports.Integration = require('./structures/Integration'); exports.IntegrationApplication = require('./structures/IntegrationApplication'); -exports.Interaction = require('./structures/Interaction'); +exports.BaseInteraction = require('./structures/BaseInteraction'); exports.InteractionCollector = require('./structures/InteractionCollector'); exports.InteractionResponse = require('./structures/InteractionResponse'); exports.InteractionWebhook = require('./structures/InteractionWebhook'); diff --git a/packages/discord.js/src/managers/ChannelManager.js b/packages/discord.js/src/managers/ChannelManager.js index 5658b6a43..10eea1720 100644 --- a/packages/discord.js/src/managers/ChannelManager.js +++ b/packages/discord.js/src/managers/ChannelManager.js @@ -3,7 +3,7 @@ const process = require('node:process'); const { Routes } = require('discord-api-types/v10'); const CachedManager = require('./CachedManager'); -const { Channel } = require('../structures/Channel'); +const { BaseChannel } = require('../structures/BaseChannel'); const { createChannel } = require('../util/Channels'); const { ThreadChannelTypes } = require('../util/Constants'); const Events = require('../util/Events'); @@ -16,7 +16,7 @@ let cacheWarningEmitted = false; */ class ChannelManager extends CachedManager { constructor(client, iterable) { - super(client, Channel, iterable); + super(client, BaseChannel, iterable); const defaultCaching = this._cache.constructor.name === 'Collection' || this._cache.maxSize === undefined || @@ -32,7 +32,7 @@ class ChannelManager extends CachedManager { /** * The cache of Channels - * @type {Collection} + * @type {Collection} * @name ChannelManager#cache */ @@ -75,7 +75,7 @@ class ChannelManager extends CachedManager { * Data that can be resolved to give a Channel object. This can be: * * A Channel object * * A Snowflake - * @typedef {Channel|Snowflake} ChannelResolvable + * @typedef {BaseChannel|Snowflake} ChannelResolvable */ /** @@ -84,7 +84,7 @@ class ChannelManager extends CachedManager { * @memberof ChannelManager * @instance * @param {ChannelResolvable} channel The channel resolvable to resolve - * @returns {?Channel} + * @returns {?BaseChannel} */ /** @@ -107,7 +107,7 @@ class ChannelManager extends CachedManager { * Obtains a channel from Discord, or the channel cache if it's already available. * @param {Snowflake} id The channel's id * @param {FetchChannelOptions} [options] Additional options for this fetch - * @returns {Promise} + * @returns {Promise} * @example * // Fetch a channel by its id * client.channels.fetch('222109930545610754') diff --git a/packages/discord.js/src/structures/AutocompleteInteraction.js b/packages/discord.js/src/structures/AutocompleteInteraction.js index 403fc97bd..e5674367d 100644 --- a/packages/discord.js/src/structures/AutocompleteInteraction.js +++ b/packages/discord.js/src/structures/AutocompleteInteraction.js @@ -1,15 +1,15 @@ 'use strict'; const { InteractionResponseType, Routes } = require('discord-api-types/v10'); +const BaseInteraction = require('./BaseInteraction'); const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver'); -const Interaction = require('./Interaction'); const { ErrorCodes } = require('../errors'); /** * Represents an autocomplete interaction. - * @extends {Interaction} + * @extends {BaseInteraction} */ -class AutocompleteInteraction extends Interaction { +class AutocompleteInteraction extends BaseInteraction { constructor(client, data) { super(client, data); diff --git a/packages/discord.js/src/structures/Channel.js b/packages/discord.js/src/structures/BaseChannel.js similarity index 95% rename from packages/discord.js/src/structures/Channel.js rename to packages/discord.js/src/structures/BaseChannel.js index 67e497e1a..76ed7c7e9 100644 --- a/packages/discord.js/src/structures/Channel.js +++ b/packages/discord.js/src/structures/BaseChannel.js @@ -10,7 +10,7 @@ const { ThreadChannelTypes } = require('../util/Constants'); * @extends {Base} * @abstract */ -class Channel extends Base { +class BaseChannel extends Base { constructor(client, data, immediatePatch = true) { super(client); @@ -81,7 +81,7 @@ class Channel extends Base { /** * Deletes this channel. - * @returns {Promise} + * @returns {Promise} * @example * // Delete the channel * channel.delete() @@ -96,7 +96,7 @@ class Channel extends Base { /** * Fetches this channel. * @param {boolean} [force=true] Whether to skip the cache check and request the API - * @returns {Promise} + * @returns {Promise} */ fetch(force = true) { return this.client.channels.fetch(this.id, { force }); @@ -139,7 +139,7 @@ class Channel extends Base { } } -exports.Channel = Channel; +exports.BaseChannel = BaseChannel; /** * @external APIChannel diff --git a/packages/discord.js/src/structures/Interaction.js b/packages/discord.js/src/structures/BaseInteraction.js similarity index 98% rename from packages/discord.js/src/structures/Interaction.js rename to packages/discord.js/src/structures/BaseInteraction.js index 38e7330c6..1bdd14431 100644 --- a/packages/discord.js/src/structures/Interaction.js +++ b/packages/discord.js/src/structures/BaseInteraction.js @@ -8,8 +8,9 @@ const PermissionsBitField = require('../util/PermissionsBitField'); /** * Represents an interaction. * @extends {Base} + * @abstract */ -class Interaction extends Base { +class BaseInteraction extends Base { constructor(client, data) { super(client); @@ -28,7 +29,7 @@ class Interaction extends Base { /** * The interaction's token * @type {string} - * @name Interaction#token + * @name BaseInteraction#token * @readonly */ Object.defineProperty(this, 'token', { value: data.token }); @@ -246,4 +247,4 @@ class Interaction extends Base { } } -module.exports = Interaction; +module.exports = BaseInteraction; diff --git a/packages/discord.js/src/structures/CommandInteraction.js b/packages/discord.js/src/structures/CommandInteraction.js index 042533a37..ec6ef404b 100644 --- a/packages/discord.js/src/structures/CommandInteraction.js +++ b/packages/discord.js/src/structures/CommandInteraction.js @@ -2,17 +2,17 @@ const { Collection } = require('@discordjs/collection'); const Attachment = require('./Attachment'); -const Interaction = require('./Interaction'); +const BaseInteraction = require('./BaseInteraction'); const InteractionWebhook = require('./InteractionWebhook'); const InteractionResponses = require('./interfaces/InteractionResponses'); /** * Represents a command interaction. - * @extends {Interaction} + * @extends {BaseInteraction} * @implements {InteractionResponses} * @abstract */ -class CommandInteraction extends Interaction { +class CommandInteraction extends BaseInteraction { constructor(client, data) { super(client, data); @@ -86,7 +86,7 @@ class CommandInteraction extends Interaction { * @property {Collection} [users] The resolved users * @property {Collection} [members] The resolved guild members * @property {Collection} [roles] The resolved roles - * @property {Collection} [channels] The resolved channels + * @property {Collection} [channels] The resolved channels * @property {Collection} [messages] The resolved messages * @property {Collection} [attachments] The resolved attachments */ diff --git a/packages/discord.js/src/structures/DMChannel.js b/packages/discord.js/src/structures/DMChannel.js index 81da5e8b8..b5452ca09 100644 --- a/packages/discord.js/src/structures/DMChannel.js +++ b/packages/discord.js/src/structures/DMChannel.js @@ -2,17 +2,17 @@ const { userMention } = require('@discordjs/builders'); const { ChannelType } = require('discord-api-types/v10'); -const { Channel } = require('./Channel'); +const { BaseChannel } = require('./BaseChannel'); const TextBasedChannel = require('./interfaces/TextBasedChannel'); const MessageManager = require('../managers/MessageManager'); const Partials = require('../util/Partials'); /** * Represents a direct message channel between two users. - * @extends {Channel} + * @extends {BaseChannel} * @implements {TextBasedChannel} */ -class DMChannel extends Channel { +class DMChannel extends BaseChannel { constructor(client, data) { super(client, data); diff --git a/packages/discord.js/src/structures/DirectoryChannel.js b/packages/discord.js/src/structures/DirectoryChannel.js index f024400f1..870eff955 100644 --- a/packages/discord.js/src/structures/DirectoryChannel.js +++ b/packages/discord.js/src/structures/DirectoryChannel.js @@ -1,12 +1,12 @@ 'use strict'; -const { Channel } = require('./Channel'); +const { BaseChannel } = require('./BaseChannel'); /** * Represents a channel that displays a directory of guilds. - * @extends {Channel} + * @extends {BaseChannel} */ -class DirectoryChannel extends Channel { +class DirectoryChannel extends BaseChannel { constructor(guild, data, client) { super(client, data); diff --git a/packages/discord.js/src/structures/GuildAuditLogsEntry.js b/packages/discord.js/src/structures/GuildAuditLogsEntry.js index b0f2fb18a..68bb66545 100644 --- a/packages/discord.js/src/structures/GuildAuditLogsEntry.js +++ b/packages/discord.js/src/structures/GuildAuditLogsEntry.js @@ -48,7 +48,7 @@ const Targets = { * * An application command * * An object with an id key if target was deleted or fake entity * * An object where the keys represent either the new value or the old value - * @typedef {?(Object|Guild|Channel|User|Role|Invite|Webhook|GuildEmoji|Message|Integration|StageInstance|Sticker| + * @typedef {?(Object|Guild|BaseChannel|User|Role|Invite|Webhook|GuildEmoji|Message|Integration|StageInstance|Sticker| * GuildScheduledEvent|ApplicationCommand)} AuditLogEntryTarget */ diff --git a/packages/discord.js/src/structures/GuildChannel.js b/packages/discord.js/src/structures/GuildChannel.js index 3b557e790..73c5bcf6e 100644 --- a/packages/discord.js/src/structures/GuildChannel.js +++ b/packages/discord.js/src/structures/GuildChannel.js @@ -1,7 +1,7 @@ 'use strict'; const { PermissionFlagsBits } = require('discord-api-types/v10'); -const { Channel } = require('./Channel'); +const { BaseChannel } = require('./BaseChannel'); const { Error, ErrorCodes } = require('../errors'); const PermissionOverwriteManager = require('../managers/PermissionOverwriteManager'); const { VoiceBasedChannelTypes } = require('../util/Constants'); @@ -14,10 +14,10 @@ const PermissionsBitField = require('../util/PermissionsBitField'); * - {@link CategoryChannel} * - {@link NewsChannel} * - {@link StageChannel} - * @extends {Channel} + * @extends {BaseChannel} * @abstract */ -class GuildChannel extends Channel { +class GuildChannel extends BaseChannel { constructor(guild, data, client, immediatePatch = true) { super(guild?.client ?? client, data, false); diff --git a/packages/discord.js/src/structures/InteractionCollector.js b/packages/discord.js/src/structures/InteractionCollector.js index a9645af02..92f4d63a9 100644 --- a/packages/discord.js/src/structures/InteractionCollector.js +++ b/packages/discord.js/src/structures/InteractionCollector.js @@ -137,7 +137,7 @@ class InteractionCollector extends Collector { /** * Handles an incoming interaction for possible collection. - * @param {Interaction} interaction The interaction to possibly collect + * @param {BaseInteraction} interaction The interaction to possibly collect * @returns {?Snowflake} * @private */ @@ -145,7 +145,7 @@ class InteractionCollector extends Collector { /** * Emitted whenever an interaction is collected. * @event InteractionCollector#collect - * @param {Interaction} interaction The interaction that was collected + * @param {BaseInteraction} interaction The interaction that was collected */ if (this.interactionType && interaction.type !== this.interactionType) return null; if (this.componentType && interaction.componentType !== this.componentType) return null; @@ -159,14 +159,14 @@ class InteractionCollector extends Collector { /** * Handles an interaction for possible disposal. - * @param {Interaction} interaction The interaction that could be disposed of + * @param {BaseInteraction} interaction The interaction that could be disposed of * @returns {?Snowflake} */ dispose(interaction) { /** * Emitted whenever an interaction is disposed of. * @event InteractionCollector#dispose - * @param {Interaction} interaction The interaction that was disposed of + * @param {BaseInteraction} interaction The interaction that was disposed of */ if (this.type && interaction.type !== this.type) return null; if (this.componentType && interaction.componentType !== this.componentType) return null; diff --git a/packages/discord.js/src/structures/InteractionResponse.js b/packages/discord.js/src/structures/InteractionResponse.js index 820be6e7d..9ea8ee541 100644 --- a/packages/discord.js/src/structures/InteractionResponse.js +++ b/packages/discord.js/src/structures/InteractionResponse.js @@ -8,14 +8,14 @@ const { ErrorCodes } = require('../errors'); */ class InteractionResponse { /** - * @param {Interaction} interaction The interaction associated with this response + * @param {BaseInteraction} interaction The interaction associated with this response * @param {Snowflake?} id The interaction id associated with the original response * @private */ constructor(interaction, id) { /** * The interaction associated with the interaction response - * @type {Interaction} + * @type {BaseInteraction} */ this.interaction = interaction; /** diff --git a/packages/discord.js/src/structures/Invite.js b/packages/discord.js/src/structures/Invite.js index d0e9602c7..f95d5681b 100644 --- a/packages/discord.js/src/structures/Invite.js +++ b/packages/discord.js/src/structures/Invite.js @@ -169,7 +169,7 @@ class Invite extends Base { if ('channel' in data) { /** * The channel this invite is for - * @type {?Channel} + * @type {?BaseChannel} */ this.channel = this.client.channels._add(data.channel, this.guild, { cache: false }) ?? diff --git a/packages/discord.js/src/structures/MessageComponentInteraction.js b/packages/discord.js/src/structures/MessageComponentInteraction.js index f2598fe99..fbf0b6e88 100644 --- a/packages/discord.js/src/structures/MessageComponentInteraction.js +++ b/packages/discord.js/src/structures/MessageComponentInteraction.js @@ -1,6 +1,6 @@ 'use strict'; -const Interaction = require('./Interaction'); +const BaseInteraction = require('./BaseInteraction'); const InteractionWebhook = require('./InteractionWebhook'); const InteractionResponses = require('./interfaces/InteractionResponses'); const { lazy } = require('../util/Util'); @@ -9,10 +9,10 @@ const getMessage = lazy(() => require('./Message').Message); /** * Represents a message component interaction. - * @extends {Interaction} + * @extends {BaseInteraction} * @implements {InteractionResponses} */ -class MessageComponentInteraction extends Interaction { +class MessageComponentInteraction extends BaseInteraction { constructor(client, data) { super(client, data); diff --git a/packages/discord.js/src/structures/MessageMentions.js b/packages/discord.js/src/structures/MessageMentions.js index 1845c0018..ca5c720a1 100644 --- a/packages/discord.js/src/structures/MessageMentions.js +++ b/packages/discord.js/src/structures/MessageMentions.js @@ -115,7 +115,7 @@ class MessageMentions { /** * Cached channels for {@link MessageMentions#channels} - * @type {?Collection} + * @type {?Collection} * @private */ this._channels = null; @@ -179,7 +179,7 @@ class MessageMentions { /** * Any channels that were mentioned * Order as they appear first in the message content - * @type {Collection} + * @type {Collection} * @readonly */ get channels() { diff --git a/packages/discord.js/src/structures/MessagePayload.js b/packages/discord.js/src/structures/MessagePayload.js index 37edf4818..07a46de1b 100644 --- a/packages/discord.js/src/structures/MessagePayload.js +++ b/packages/discord.js/src/structures/MessagePayload.js @@ -7,7 +7,9 @@ const ActionRowBuilder = require('./ActionRowBuilder'); const { RangeError, ErrorCodes } = require('../errors'); const DataResolver = require('../util/DataResolver'); const MessageFlagsBitField = require('../util/MessageFlagsBitField'); -const { basename, cloneObject, verifyString } = require('../util/Util'); +const { basename, cloneObject, verifyString, lazy } = require('../util/Util'); + +const getBaseInteraction = lazy(() => require('./BaseInteraction')); /** * Represents a message to be sent to the API. @@ -86,14 +88,14 @@ class MessagePayload { } /** - * Whether or not the target is an {@link Interaction} or an {@link InteractionWebhook} + * Whether or not the target is an {@link BaseInteraction} or an {@link InteractionWebhook} * @type {boolean} * @readonly */ get isInteraction() { - const Interaction = require('./Interaction'); + const BaseInteraction = getBaseInteraction(); const InteractionWebhook = require('./InteractionWebhook'); - return this.target instanceof Interaction || this.target instanceof InteractionWebhook; + return this.target instanceof BaseInteraction || this.target instanceof InteractionWebhook; } /** @@ -277,7 +279,7 @@ module.exports = MessagePayload; /** * A target for a message. - * @typedef {TextBasedChannels|User|GuildMember|Webhook|WebhookClient|Interaction|InteractionWebhook| + * @typedef {TextBasedChannels|User|GuildMember|Webhook|WebhookClient|BaseInteraction|InteractionWebhook| * Message|MessageManager} MessageTarget */ diff --git a/packages/discord.js/src/structures/ModalSubmitInteraction.js b/packages/discord.js/src/structures/ModalSubmitInteraction.js index 8362448ba..0af1e4d91 100644 --- a/packages/discord.js/src/structures/ModalSubmitInteraction.js +++ b/packages/discord.js/src/structures/ModalSubmitInteraction.js @@ -1,6 +1,6 @@ 'use strict'; -const Interaction = require('./Interaction'); +const BaseInteraction = require('./BaseInteraction'); const InteractionWebhook = require('./InteractionWebhook'); const ModalSubmitFields = require('./ModalSubmitFields'); const InteractionResponses = require('./interfaces/InteractionResponses'); @@ -25,7 +25,7 @@ const getMessage = lazy(() => require('./Message').Message); * Represents a modal interaction * @implements {InteractionResponses} */ -class ModalSubmitInteraction extends Interaction { +class ModalSubmitInteraction extends BaseInteraction { constructor(client, data) { super(client, data); /** diff --git a/packages/discord.js/src/structures/PartialGroupDMChannel.js b/packages/discord.js/src/structures/PartialGroupDMChannel.js index a946c5a64..92d7d1ea3 100644 --- a/packages/discord.js/src/structures/PartialGroupDMChannel.js +++ b/packages/discord.js/src/structures/PartialGroupDMChannel.js @@ -1,13 +1,13 @@ 'use strict'; -const { Channel } = require('./Channel'); +const { BaseChannel } = require('./BaseChannel'); const { Error, ErrorCodes } = require('../errors'); /** * Represents a Partial Group DM Channel on Discord. - * @extends {Channel} + * @extends {BaseChannel} */ -class PartialGroupDMChannel extends Channel { +class PartialGroupDMChannel extends BaseChannel { constructor(client, data) { super(client, data); diff --git a/packages/discord.js/src/structures/ThreadChannel.js b/packages/discord.js/src/structures/ThreadChannel.js index 65cf5c886..2568dcabf 100644 --- a/packages/discord.js/src/structures/ThreadChannel.js +++ b/packages/discord.js/src/structures/ThreadChannel.js @@ -1,7 +1,7 @@ 'use strict'; const { ChannelType, PermissionFlagsBits, Routes } = require('discord-api-types/v10'); -const { Channel } = require('./Channel'); +const { BaseChannel } = require('./BaseChannel'); const TextBasedChannel = require('./interfaces/TextBasedChannel'); const { RangeError, ErrorCodes } = require('../errors'); const MessageManager = require('../managers/MessageManager'); @@ -9,10 +9,10 @@ const ThreadMemberManager = require('../managers/ThreadMemberManager'); /** * Represents a thread channel on Discord. - * @extends {Channel} + * @extends {BaseChannel} * @implements {TextBasedChannel} */ -class ThreadChannel extends Channel { +class ThreadChannel extends BaseChannel { constructor(guild, data, client, fromInteraction = false) { super(guild?.client ?? client, data, false); diff --git a/packages/discord.js/src/structures/interfaces/InteractionResponses.js b/packages/discord.js/src/structures/interfaces/InteractionResponses.js index e1fc4a9a0..6e66ba325 100644 --- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js +++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js @@ -20,7 +20,7 @@ const MessagePayload = require('../MessagePayload'); */ class InteractionResponses { /** - * Options for deferring the reply to an {@link Interaction}. + * Options for deferring the reply to an {@link BaseInteraction}. * @typedef {Object} InteractionDeferReplyOptions * @property {boolean} [ephemeral] Whether the reply should be ephemeral * @property {boolean} [fetchReply] Whether to fetch the reply @@ -33,7 +33,7 @@ class InteractionResponses { */ /** - * Options for a reply to an {@link Interaction}. + * Options for a reply to an {@link BaseInteraction}. * @typedef {BaseMessageOptions} InteractionReplyOptions * @property {boolean} [ephemeral] Whether the reply should be ephemeral * @property {boolean} [fetchReply] Whether to fetch the reply diff --git a/packages/discord.js/src/util/Util.js b/packages/discord.js/src/util/Util.js index 8d4dd7c55..2f4773370 100644 --- a/packages/discord.js/src/util/Util.js +++ b/packages/discord.js/src/util/Util.js @@ -445,14 +445,14 @@ function discordSort(collection) { /** * Sets the position of a Channel or Role. - * @param {Channel|Role} item Object to set the position of + * @param {BaseChannel|Role} item Object to set the position of * @param {number} position New position for the object * @param {boolean} relative Whether `position` is relative to its current position - * @param {Collection} sorted A collection of the objects sorted properly + * @param {Collection} sorted A collection of the objects sorted properly * @param {Client} client The client to use to patch the data * @param {string} route Route to call PATCH on * @param {string} [reason] Reason for the change - * @returns {Promise} Updated item list, with `id` and `position` properties + * @returns {Promise} Updated item list, with `id` and `position` properties * @private */ async function setPosition(item, position, relative, sorted, client, route, reason) { diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index ecd2d8a85..b5beeff3a 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -416,7 +416,7 @@ export interface InteractionResponseFields export type BooleanCache = T extends 'cached' ? true : false; -export abstract class CommandInteraction extends Interaction { +export abstract class CommandInteraction extends BaseInteraction { public type: InteractionType.ApplicationCommand; public get command(): ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; public options: Omit< @@ -481,10 +481,10 @@ export class InteractionResponse { public interaction: Interaction>; public client: Client; public id: Snowflake; - public awaitMessageComponent( + public awaitMessageComponent( options?: AwaitMessageCollectorOptionsParams, ): Promise[T]>; - public createMessageComponentCollector( + public createMessageComponentCollector( options?: MessageCollectorOptionsParams, ): InteractionCollector[T]>; } @@ -746,7 +746,7 @@ export class CategoryChannel extends GuildChannel { export type CategoryChannelResolvable = Snowflake | CategoryChannel; -export abstract class Channel extends Base { +export abstract class BaseChannel extends Base { public constructor(client: Client, data?: RawChannelData, immediatePatch?: boolean); public get createdAt(): Date | null; public get createdTimestamp(): number | null; @@ -932,7 +932,7 @@ export class ChatInputCommandInteraction e public toString(): string; } -export class AutocompleteInteraction extends Interaction { +export class AutocompleteInteraction extends BaseInteraction { public type: InteractionType.ApplicationCommandAutocomplete; public get command(): ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; public channelId: Snowflake; @@ -1045,7 +1045,7 @@ export class DataResolver extends null { public static resolveGuildTemplateCode(data: GuildTemplateResolvable): string; } -export class DMChannel extends TextBasedChannelMixin(Channel, [ +export class DMChannel extends TextBasedChannelMixin(BaseChannel, [ 'bulkDelete', 'fetchWebhooks', 'createWebhook', @@ -1226,7 +1226,7 @@ export class GuildBan extends Base { public fetch(force?: boolean): Promise; } -export abstract class GuildChannel extends Channel { +export abstract class GuildChannel extends BaseChannel { public constructor(guild: Guild, data?: RawGuildChannelData, client?: Client, immediatePatch?: boolean); private memberPermissions(member: GuildMember, checkAdmin: boolean): Readonly; private rolePermissions(role: Role, checkAdmin: boolean): Readonly; @@ -1486,7 +1486,7 @@ export type CacheTypeReducer< ? PresentType : Fallback; -export type AnyInteraction = +export type Interaction = | ChatInputCommandInteraction | MessageContextMenuCommandInteraction | UserContextMenuCommandInteraction @@ -1495,7 +1495,7 @@ export type AnyInteraction = | AutocompleteInteraction | ModalSubmitInteraction; -export class Interaction extends Base { +export class BaseInteraction extends Base { // This a technique used to brand different cached types. Or else we'll get `never` errors on typeguard checks. private readonly _cacheType: Cached; protected constructor(client: Client, data: RawInteractionData); @@ -1521,9 +1521,9 @@ export class Interaction extends Base { public memberPermissions: CacheTypeReducer>; public locale: Locale; public guildLocale: CacheTypeReducer; - public inGuild(): this is Interaction<'raw' | 'cached'>; - public inCachedGuild(): this is Interaction<'cached'>; - public inRawGuild(): this is Interaction<'raw'>; + public inGuild(): this is BaseInteraction<'raw' | 'cached'>; + public inCachedGuild(): this is BaseInteraction<'cached'>; + public inRawGuild(): this is BaseInteraction<'raw'>; public isButton(): this is ButtonInteraction; public isChatInputCommand(): this is ChatInputCommandInteraction; public isContextMenuCommand(): this is ContextMenuCommandInteraction; @@ -1533,7 +1533,11 @@ export class Interaction extends Base { public isRepliable(): this is this & InteractionResponseFields; } -export class InteractionCollector extends Collector]> { +export class InteractionCollector extends Collector< + Snowflake, + T, + [Collection] +> { public constructor(client: Client, options?: InteractionCollectorOptions); private _handleMessageDeletion(message: Message): void; private _handleChannelDeletion(channel: NonThreadGuildBasedChannel): void; @@ -1628,7 +1632,7 @@ export class LimitedCollection extends Collection { public keepOverLimit: ((value: V, key: K, collection: this) => boolean) | null; } -export type MessageComponentType = Exclude; +export type MessageComponentType = Exclude; export type MessageCollectorOptionsParams = | { @@ -1657,8 +1661,6 @@ export type WrapBooleanCache = If; export interface MappedInteractionTypes { [ComponentType.Button]: ButtonInteraction>; [ComponentType.SelectMenu]: SelectMenuInteraction>; - [ComponentType.ActionRow]: MessageComponentInteraction>; - [ComponentType.TextInput]: never; } export class Message extends Base { @@ -1705,12 +1707,12 @@ export class Message extends Base { public webhookId: Snowflake | null; public flags: Readonly; public reference: MessageReference | null; - public awaitMessageComponent( + public awaitMessageComponent( options?: AwaitMessageCollectorOptionsParams, ): Promise[T]>; public awaitReactions(options?: AwaitReactionsOptions): Promise>; public createReactionCollector(options?: ReactionCollectorOptions): ReactionCollector; - public createMessageComponentCollector( + public createMessageComponentCollector( options?: MessageCollectorOptionsParams, ): InteractionCollector[T]>; public delete(): Promise; @@ -1777,7 +1779,7 @@ export class MessageCollector extends Collector extends Interaction { +export class MessageComponentInteraction extends BaseInteraction { protected constructor(client: Client, data: RawMessageComponentInteractionData); public type: InteractionType.MessageComponent; public get component(): CacheTypeReducer< @@ -1854,11 +1856,11 @@ export class MessageMentions { everyone: boolean, repliedUser?: APIUser | User, ); - private _channels: Collection | null; + private _channels: Collection | null; private readonly _content: string; private _members: Collection | null; - public get channels(): Collection; + public get channels(): Collection; public readonly client: Client; public everyone: boolean; public readonly guild: Guild; @@ -1968,7 +1970,7 @@ export interface ModalMessageModalSubmitInteraction; } -export class ModalSubmitInteraction extends Interaction { +export class ModalSubmitInteraction extends BaseInteraction { private constructor(client: Client, data: APIModalSubmitInteraction); public type: InteractionType.ModalSubmit; public readonly customId: string; @@ -2011,7 +2013,7 @@ export class OAuth2Guild extends BaseGuild { public permissions: Readonly; } -export class PartialGroupDMChannel extends Channel { +export class PartialGroupDMChannel extends BaseChannel { private constructor(client: Client, data: RawPartialGroupDMChannelData); public type: ChannelType.GroupDM; public name: string | null; @@ -2306,7 +2308,7 @@ export class StageChannel extends BaseGuildVoiceChannel { public setTopic(topic: string): Promise; } -export class DirectoryChannel extends Channel { +export class DirectoryChannel extends BaseChannel { public guild: InviteGuild; public guildId: Snowflake; public name: string; @@ -2487,7 +2489,7 @@ export interface PrivateThreadChannel extends ThreadChannel { type: ChannelType.GuildPrivateThread; } -export class ThreadChannel extends TextBasedChannelMixin(Channel, ['fetchWebhooks', 'createWebhook', 'setNSFW']) { +export class ThreadChannel extends TextBasedChannelMixin(BaseChannel, ['fetchWebhooks', 'createWebhook', 'setNSFW']) { private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client, fromInteraction?: boolean); public archived: boolean | null; public get archivedAt(): Date | null; @@ -2648,7 +2650,7 @@ export function parseEmoji(text: string): { animated: boolean; name: string; id: export function resolveColor(color: ColorResolvable): number; export function resolvePartialEmoji(emoji: EmojiIdentifierResolvable): Partial | null; export function verifyString(data: string, error?: typeof Error, errorMessage?: string, allowEmpty?: boolean): string; -export function setPosition( +export function setPosition( item: T, position: number, relative: boolean, @@ -2677,7 +2679,7 @@ export interface CreateChannelOptions { fromInteraction?: boolean; } -export function createChannel(client: Client, data: APIChannel, options?: CreateChannelOptions): AnyChannel; +export function createChannel(client: Client, data: APIChannel, options?: CreateChannelOptions): Channel; export function createComponent( data: APIMessageComponent & { type: T }, @@ -3285,9 +3287,9 @@ export class CategoryChannelChildManager extends DataManager< public create(options: CategoryCreateChannelOptions): Promise; } -export class ChannelManager extends CachedManager { +export class ChannelManager extends CachedManager { private constructor(client: Client, iterable: Iterable); - public fetch(id: Snowflake, options?: FetchChannelOptions): Promise; + public fetch(id: Snowflake, options?: FetchChannelOptions): Promise; } export type FetchGuildApplicationCommandFetchOptions = Omit; @@ -3615,7 +3617,7 @@ export interface TextBasedChannelFields extends PartialTextBasedChannelFields { lastPinTimestamp: number | null; get lastPinAt(): Date | null; messages: MessageManager; - awaitMessageComponent( + awaitMessageComponent( options?: AwaitMessageCollectorOptionsParams, ): Promise; awaitMessages(options?: AwaitMessagesOptions): Promise>; @@ -3623,7 +3625,7 @@ export interface TextBasedChannelFields extends PartialTextBasedChannelFields { messages: Collection | readonly MessageResolvable[] | number, filterOld?: boolean, ): Promise>; - createMessageComponentCollector( + createMessageComponentCollector( options?: MessageChannelCollectorOptionsParams, ): InteractionCollector; createMessageCollector(options?: MessageCollectorOptions): MessageCollector; @@ -3896,7 +3898,7 @@ export interface AuditLogChange { export type Awaitable = T | PromiseLike; -export type AwaitMessageComponentOptions = Omit< +export type AwaitMessageComponentOptions = Omit< MessageComponentCollectorOptions, 'max' | 'maxComponents' | 'maxUsers' >; @@ -4038,7 +4040,7 @@ export interface ChannelPosition { } export type GuildTextChannelResolvable = TextChannel | NewsChannel | Snowflake; -export type ChannelResolvable = AnyChannel | Snowflake; +export type ChannelResolvable = Channel | Snowflake; export interface ChannelWebhookCreateOptions { name: string; @@ -4115,7 +4117,7 @@ export interface ClientEvents { userUpdate: [oldUser: User | PartialUser, newUser: User]; voiceStateUpdate: [oldState: VoiceState, newState: VoiceState]; webhookUpdate: [channel: TextChannel | NewsChannel | VoiceChannel]; - interactionCreate: [interaction: AnyInteraction]; + interactionCreate: [interaction: Interaction]; shardDisconnect: [closeEvent: CloseEvent, shardId: number]; shardError: [error: Error, shardId: number]; shardReady: [shardId: number, unavailableGuilds: Set | undefined]; @@ -4218,7 +4220,7 @@ export interface CommandInteractionResolvedData; members?: Collection>; roles?: Collection>; - channels?: Collection>; + channels?: Collection>; messages?: Collection>; attachments?: Collection; } @@ -4857,7 +4859,12 @@ export interface IntegrationAccount { export type IntegrationType = 'twitch' | 'youtube' | 'discord'; -export interface InteractionCollectorOptions +export type CollectedInteraction = + | SelectMenuInteraction + | ButtonInteraction + | ModalSubmitInteraction; + +export interface InteractionCollectorOptions extends CollectorOptions<[T, Collection]> { channel?: TextBasedChannelResolvable; componentType?: ComponentType; @@ -4962,12 +4969,17 @@ export type MessageComponent = | ButtonComponent | SelectMenuComponent; -export type MessageComponentCollectorOptions = Omit< +export type CollectedMessageInteraction = Exclude< + CollectedInteraction, + ModalSubmitInteraction +>; + +export type MessageComponentCollectorOptions = Omit< InteractionCollectorOptions, 'channel' | 'message' | 'guild' | 'interactionType' >; -export type MessageChannelComponentCollectorOptions = Omit< +export type MessageChannelComponentCollectorOptions = Omit< InteractionCollectorOptions, 'channel' | 'guild' | 'interactionType' >; @@ -5367,7 +5379,7 @@ export interface LimitedCollectionOptions { keepOverLimit?: (value: V, key: K, collection: LimitedCollection) => boolean; } -export type AnyChannel = +export type Channel = | CategoryChannel | DMChannel | PartialDMChannel @@ -5378,13 +5390,13 @@ export type AnyChannel = | AnyThreadChannel | VoiceChannel; -export type TextBasedChannel = Extract; +export type TextBasedChannel = Extract; export type TextBasedChannelTypes = TextBasedChannel['type']; -export type VoiceBasedChannel = Extract; +export type VoiceBasedChannel = Extract; -export type GuildBasedChannel = Extract; +export type GuildBasedChannel = Extract; export type NonCategoryGuildBasedChannel = Exclude; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index ea224c443..7f4aa2ee7 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -127,6 +127,7 @@ import { UserContextMenuCommandInteraction, AnyThreadChannel, ThreadMemberManager, + CollectedMessageInteraction, } from '.'; import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd'; import { UnsafeButtonBuilder, UnsafeEmbedBuilder, UnsafeSelectMenuBuilder } from '@discordjs/builders'; @@ -754,13 +755,13 @@ client.on('messageCreate', async message => { const defaultCollector = message.createMessageComponentCollector(); expectAssignable>(message.awaitMessageComponent()); expectAssignable>(channel.awaitMessageComponent()); - expectAssignable>(defaultCollector); + expectAssignable>(defaultCollector); // Verify that additional options don't affect default collector types. const semiDefaultCollector = message.createMessageComponentCollector({ time: 10000 }); - expectType>(semiDefaultCollector); + expectType>(semiDefaultCollector); const semiDefaultCollectorChannel = message.createMessageComponentCollector({ time: 10000 }); - expectType>(semiDefaultCollectorChannel); + expectType>(semiDefaultCollectorChannel); // Verify that interaction collector options can't be used. message.createMessageComponentCollector({ @@ -771,7 +772,7 @@ client.on('messageCreate', async message => { // Make sure filter parameters are properly inferred. message.createMessageComponentCollector({ filter: i => { - expectType(i); + expectType(i); return true; }, }); @@ -794,7 +795,7 @@ client.on('messageCreate', async message => { message.awaitMessageComponent({ filter: i => { - expectType(i); + expectType(i); return true; }, }); @@ -830,7 +831,7 @@ client.on('messageCreate', async message => { channel.awaitMessageComponent({ filter: i => { - expectType>(i); + expectType>(i); return true; }, });