diff --git a/packages/discord.js/src/index.js b/packages/discord.js/src/index.js index c44e2af4d..e28a0e599 100644 --- a/packages/discord.js/src/index.js +++ b/packages/discord.js/src/index.js @@ -122,7 +122,7 @@ exports.Invite = require('./structures/Invite'); exports.InviteStageInstance = require('./structures/InviteStageInstance'); exports.InviteGuild = require('./structures/InviteGuild'); exports.Message = require('./structures/Message').Message; -exports.MessageAttachment = require('./structures/MessageAttachment'); +exports.Attachment = require('./structures/Attachment'); exports.ModalBuilder = require('./structures/ModalBuilder'); exports.MessageCollector = require('./structures/MessageCollector'); exports.MessageComponentInteraction = require('./structures/MessageComponentInteraction'); diff --git a/packages/discord.js/src/managers/GuildStickerManager.js b/packages/discord.js/src/managers/GuildStickerManager.js index eecbfbb29..1d8c73ad8 100644 --- a/packages/discord.js/src/managers/GuildStickerManager.js +++ b/packages/discord.js/src/managers/GuildStickerManager.js @@ -41,7 +41,7 @@ class GuildStickerManager extends CachedManager { /** * Creates a new custom sticker in the guild. - * @param {BufferResolvable|Stream|FileOptions|MessageAttachment} file The file for the sticker + * @param {BufferResolvable|Stream|FileOptions|Attachment} file The file for the sticker * @param {string} name The name for the sticker * @param {string} tags The Discord name of a unicode emoji representing the sticker's expression * @param {GuildStickerCreateOptions} [options] Options diff --git a/packages/discord.js/src/structures/MessageAttachment.js b/packages/discord.js/src/structures/Attachment.js similarity index 91% rename from packages/discord.js/src/structures/MessageAttachment.js rename to packages/discord.js/src/structures/Attachment.js index 3426a17ae..ead506c98 100644 --- a/packages/discord.js/src/structures/MessageAttachment.js +++ b/packages/discord.js/src/structures/Attachment.js @@ -3,9 +3,9 @@ const Util = require('../util/Util'); /** - * Represents an attachment in a message. + * Represents an attachment. */ -class MessageAttachment { +class Attachment { /** * @param {BufferResolvable|Stream} attachment The file * @param {string} [name=null] The name of the file, if any @@ -24,7 +24,7 @@ class MessageAttachment { /** * Sets the description of this attachment. * @param {string} description The description of the file - * @returns {MessageAttachment} This attachment + * @returns {Attachment} This attachment */ setDescription(description) { this.description = description; @@ -35,7 +35,7 @@ class MessageAttachment { * Sets the file of this attachment. * @param {BufferResolvable|Stream} attachment The file * @param {string} [name=null] The name of the file, if any - * @returns {MessageAttachment} This attachment + * @returns {Attachment} This attachment */ setFile(attachment, name = null) { this.attachment = attachment; @@ -46,7 +46,7 @@ class MessageAttachment { /** * Sets the name of this attachment. * @param {string} name The name of the file - * @returns {MessageAttachment} This attachment + * @returns {Attachment} This attachment */ setName(name) { this.name = name; @@ -56,7 +56,7 @@ class MessageAttachment { /** * Sets whether this attachment is a spoiler * @param {boolean} [spoiler=true] Whether the attachment should be marked as a spoiler - * @returns {MessageAttachment} This attachment + * @returns {Attachment} This attachment */ setSpoiler(spoiler = true) { if (spoiler === this.spoiler) return this; @@ -163,7 +163,7 @@ class MessageAttachment { } } -module.exports = MessageAttachment; +module.exports = Attachment; /** * @external APIAttachment diff --git a/packages/discord.js/src/structures/CommandInteraction.js b/packages/discord.js/src/structures/CommandInteraction.js index 9400d6351..9691f5459 100644 --- a/packages/discord.js/src/structures/CommandInteraction.js +++ b/packages/discord.js/src/structures/CommandInteraction.js @@ -1,9 +1,9 @@ 'use strict'; const { Collection } = require('@discordjs/collection'); +const Attachment = require('./Attachment'); const Interaction = require('./Interaction'); const InteractionWebhook = require('./InteractionWebhook'); -const MessageAttachment = require('./MessageAttachment'); const InteractionResponses = require('./interfaces/InteractionResponses'); /** @@ -82,7 +82,7 @@ class CommandInteraction extends Interaction { * @property {Collection} [roles] The resolved roles * @property {Collection} [channels] The resolved channels * @property {Collection} [messages] The resolved messages - * @property {Collection} [attachments] The resolved attachments + * @property {Collection} [attachments] The resolved attachments */ /** @@ -133,7 +133,7 @@ class CommandInteraction extends Interaction { if (attachments) { result.attachments = new Collection(); for (const attachment of Object.values(attachments)) { - const patched = new MessageAttachment(attachment.url, attachment.filename, attachment); + const patched = new Attachment(attachment.url, attachment.filename, attachment); result.attachments.set(attachment.id, patched); } } @@ -156,7 +156,7 @@ class CommandInteraction extends Interaction { * @property {GuildMember|APIGuildMember} [member] The resolved member * @property {GuildChannel|ThreadChannel|APIChannel} [channel] The resolved channel * @property {Role|APIRole} [role] The resolved role - * @property {MessageAttachment} [attachment] The resolved attachment + * @property {Attachment} [attachment] The resolved attachment */ /** @@ -189,7 +189,7 @@ class CommandInteraction extends Interaction { if (role) result.role = this.guild?.roles._add(role) ?? role; const attachment = resolved.attachments?.[option.value]; - if (attachment) result.attachment = new MessageAttachment(attachment.url, attachment.filename, attachment); + if (attachment) result.attachment = new Attachment(attachment.url, attachment.filename, attachment); } return result; diff --git a/packages/discord.js/src/structures/CommandInteractionOptionResolver.js b/packages/discord.js/src/structures/CommandInteractionOptionResolver.js index 6f01cf61c..8d596c17c 100644 --- a/packages/discord.js/src/structures/CommandInteractionOptionResolver.js +++ b/packages/discord.js/src/structures/CommandInteractionOptionResolver.js @@ -220,7 +220,7 @@ class CommandInteractionOptionResolver { * Gets an attachment option. * @param {string} name The name of the option. * @param {boolean} [required=false] Whether to throw an error if the option is not found. - * @returns {?MessageAttachment} The value of the option, or null if not set and not required. + * @returns {?Attachment} The value of the option, or null if not set and not required. */ getAttachment(name, required = false) { const option = this._getTypedOption(name, ApplicationCommandOptionType.Attachment, ['attachment'], required); diff --git a/packages/discord.js/src/structures/Message.js b/packages/discord.js/src/structures/Message.js index 4b0986df6..e9c484f97 100644 --- a/packages/discord.js/src/structures/Message.js +++ b/packages/discord.js/src/structures/Message.js @@ -9,11 +9,11 @@ const { MessageFlags, PermissionFlagsBits, } = require('discord-api-types/v10'); +const Attachment = require('./Attachment'); const Base = require('./Base'); const ClientApplication = require('./ClientApplication'); const Embed = require('./Embed'); const InteractionCollector = require('./InteractionCollector'); -const MessageAttachment = require('./MessageAttachment'); const Mentions = require('./MessageMentions'); const MessagePayload = require('./MessagePayload'); const ReactionCollector = require('./ReactionCollector'); @@ -154,12 +154,12 @@ class Message extends Base { if ('attachments' in data) { /** * A collection of attachments in the message - e.g. Pictures - mapped by their ids - * @type {Collection} + * @type {Collection} */ this.attachments = new Collection(); if (data.attachments) { for (const attachment of data.attachments) { - this.attachments.set(attachment.id, new MessageAttachment(attachment.url, attachment.filename, attachment)); + this.attachments.set(attachment.id, new Attachment(attachment.url, attachment.filename, attachment)); } } } else { @@ -642,9 +642,9 @@ class Message extends Base { * @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content * @property {MessageFlags} [flags] Which flags to set for the message. * Only `MessageFlags.SuppressEmbeds` can be edited. - * @property {MessageAttachment[]} [attachments] An array of attachments to keep, + * @property {Attachment[]} [attachments] An array of attachments to keep, * all attachments will be kept if omitted - * @property {FileOptions[]|BufferResolvable[]|MessageAttachment[]} [files] Files to add to the message + * @property {FileOptions[]|BufferResolvable[]|Attachment[]} [files] Files to add to the message * @property {ActionRow[]|ActionRowOptions[]} [components] * Action rows containing interactive components for the message (buttons, select menus) */ diff --git a/packages/discord.js/src/structures/MessagePayload.js b/packages/discord.js/src/structures/MessagePayload.js index 17accd15d..8a99b59a0 100644 --- a/packages/discord.js/src/structures/MessagePayload.js +++ b/packages/discord.js/src/structures/MessagePayload.js @@ -224,7 +224,7 @@ class MessagePayload { /** * Resolves a single file into an object sendable to the API. - * @param {BufferResolvable|Stream|FileOptions|MessageAttachment} fileLike Something that could be resolved to a file + * @param {BufferResolvable|Stream|FileOptions|Attachment} fileLike Something that could be resolved to a file * @returns {Promise} */ static async resolveFile(fileLike) { diff --git a/packages/discord.js/src/structures/Webhook.js b/packages/discord.js/src/structures/Webhook.js index 6b27b446b..9fc21354e 100644 --- a/packages/discord.js/src/structures/Webhook.js +++ b/packages/discord.js/src/structures/Webhook.js @@ -132,9 +132,9 @@ class Webhook { * @typedef {Object} WebhookEditMessageOptions * @property {Embed[]|APIEmbed[]} [embeds] See {@link WebhookMessageOptions#embeds} * @property {string} [content] See {@link BaseMessageOptions#content} - * @property {FileOptions[]|BufferResolvable[]|MessageAttachment[]} [files] See {@link BaseMessageOptions#files} + * @property {FileOptions[]|BufferResolvable[]|Attachment[]} [files] See {@link BaseMessageOptions#files} * @property {MessageMentionOptions} [allowedMentions] See {@link BaseMessageOptions#allowedMentions} - * @property {MessageAttachment[]} [attachments] Attachments to send with the message + * @property {Attachment[]} [attachments] Attachments to send with the message * @property {ActionRow[]|ActionRowOptions[]} [components] * Action rows containing interactive components for the message (buttons, select menus) * @property {Snowflake} [threadId] The id of the thread this message belongs to diff --git a/packages/discord.js/src/structures/interfaces/TextBasedChannel.js b/packages/discord.js/src/structures/interfaces/TextBasedChannel.js index 0aa6d2e41..d5fd397f9 100644 --- a/packages/discord.js/src/structures/interfaces/TextBasedChannel.js +++ b/packages/discord.js/src/structures/interfaces/TextBasedChannel.js @@ -61,10 +61,10 @@ class TextBasedChannel { * (see [here](https://discord.com/developers/docs/resources/channel#embed-object) for more details) * @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content * (see [here](https://discord.com/developers/docs/resources/channel#allowed-mentions-object) for more details) - * @property {FileOptions[]|BufferResolvable[]|MessageAttachment[]} [files] Files to send with the message + * @property {FileOptions[]|BufferResolvable[]|Attachment[]} [files] Files to send with the message * @property {ActionRow[]|ActionRowOptions[]} [components] * Action rows containing interactive components for the message (buttons, select menus) - * @property {MessageAttachment[]} [attachments] Attachments to send in the message + * @property {Attachment[]} [attachments] Attachments to send in the message */ /** diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 801244b0a..bd567379d 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -148,7 +148,7 @@ import { RawInviteData, RawInviteGuildData, RawInviteStageInstance, - RawMessageAttachmentData, + RawAttachmentData, RawMessageButtonInteractionData, RawMessageComponentInteractionData, RawMessageData, @@ -1645,7 +1645,7 @@ export class Message extends Base { public activity: MessageActivity | null; public applicationId: Snowflake | null; - public attachments: Collection; + public attachments: Collection; public author: User; public get channel(): If; public channelId: Snowflake; @@ -1710,8 +1710,8 @@ export class Message extends Base { public inGuild(): this is Message & this; } -export class MessageAttachment { - public constructor(attachment: BufferResolvable | Stream, name?: string, data?: RawMessageAttachmentData); +export class Attachment { + public constructor(attachment: BufferResolvable | Stream, name?: string, data?: RawAttachmentData); public attachment: BufferResolvable | Stream; public contentType: string | null; @@ -1847,7 +1847,7 @@ export class MessagePayload { options: string | MessageOptions | WebhookMessageOptions, extra?: MessageOptions | WebhookMessageOptions, ): MessagePayload; - public static resolveFile(fileLike: BufferResolvable | Stream | FileOptions | MessageAttachment): Promise; + public static resolveFile(fileLike: BufferResolvable | Stream | FileOptions | Attachment): Promise; public makeContent(): string | undefined; public resolveBody(): this; @@ -3167,7 +3167,7 @@ export class GuildStickerManager extends CachedManager); public guild: Guild; public create( - file: BufferResolvable | Stream | FileOptions | MessageAttachment, + file: BufferResolvable | Stream | FileOptions | Attachment, name: string, tags: string, options?: GuildStickerCreateOptions, @@ -3905,7 +3905,7 @@ export interface CommandInteractionOption member?: CacheTypeReducer; channel?: CacheTypeReducer; role?: CacheTypeReducer; - attachment?: MessageAttachment; + attachment?: Attachment; message?: GuildCacheMessage; } @@ -3915,7 +3915,7 @@ export interface CommandInteractionResolvedData>; channels?: Collection>; messages?: Collection>; - attachments?: Collection; + attachments?: Collection; } export declare const Colors: { @@ -4765,10 +4765,10 @@ export type MessageChannelComponentCollectorOptions; export interface MessageEditOptions { - attachments?: MessageAttachment[]; + attachments?: Attachment[]; content?: string | null; embeds?: (JSONEncodable | APIEmbed)[] | null; - files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[]; + files?: (FileOptions | BufferResolvable | Stream | Attachment)[]; flags?: BitFieldResolvable; allowedMentions?: MessageMentionOptions; components?: ( @@ -4818,10 +4818,10 @@ export interface MessageOptions { | APIActionRowComponent )[]; allowedMentions?: MessageMentionOptions; - files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[]; + files?: (FileOptions | BufferResolvable | Stream | Attachment)[]; reply?: ReplyOptions; stickers?: StickerResolvable[]; - attachments?: MessageAttachment[]; + attachments?: Attachment[]; flags?: BitFieldResolvable, number>; } diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index b9c603f2e..93ec1ebf9 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -57,7 +57,7 @@ import { Interaction, InteractionCollector, Message, - MessageAttachment, + Attachment, MessageCollector, MessageComponentInteraction, MessageReaction, @@ -584,7 +584,7 @@ client.on('messageCreate', async message => { assertIsMessage(channel.send({})); assertIsMessage(channel.send({ embeds: [] })); - const attachment = new MessageAttachment('file.png'); + const attachment = new Attachment('file.png'); const embed = new EmbedBuilder(); assertIsMessage(channel.send({ files: [attachment] })); assertIsMessage(channel.send({ embeds: [embed] })); @@ -1456,8 +1456,8 @@ expectNotAssignable>({ declare const chatInputInteraction: ChatInputCommandInteraction; -expectType(chatInputInteraction.options.getAttachment('attachment', true)); -expectType(chatInputInteraction.options.getAttachment('attachment')); +expectType(chatInputInteraction.options.getAttachment('attachment', true)); +expectType(chatInputInteraction.options.getAttachment('attachment')); declare const modal: ModalBuilder; diff --git a/packages/discord.js/typings/rawDataTypes.d.ts b/packages/discord.js/typings/rawDataTypes.d.ts index 28b2709aa..d1075e208 100644 --- a/packages/discord.js/typings/rawDataTypes.d.ts +++ b/packages/discord.js/typings/rawDataTypes.d.ts @@ -152,7 +152,7 @@ export type RawInviteStageInstance = APIInviteStageInstance; export type RawMessageData = APIMessage; export type RawPartialMessageData = GatewayMessageUpdateDispatchData; -export type RawMessageAttachmentData = APIAttachment; +export type RawAttachmentData = APIAttachment; export type RawMessagePayloadData = | RESTPostAPIChannelMessageJSONBody