mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor(MessageAttachment): use Attachment instead (#7691)
* fix: TOKEN_INVALID error not thrown at login with invalid token * refactor(MessageAttachment): Use Attachment instead * Delete a mistake * Add WebSocketManager file, deleted by error * add a new line on WebSocketManager file * fix: imports * fix: conflict with typings * chore: update reference on GuildStickerManager
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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<Snowflake, Role|APIRole>} [roles] The resolved roles
|
||||
* @property {Collection<Snowflake, Channel|APIChannel>} [channels] The resolved channels
|
||||
* @property {Collection<Snowflake, Message|APIMessage>} [messages] The resolved messages
|
||||
* @property {Collection<Snowflake, MessageAttachment>} [attachments] The resolved attachments
|
||||
* @property {Collection<Snowflake, Attachment>} [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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Snowflake, MessageAttachment>}
|
||||
* @type {Collection<Snowflake, Attachment>}
|
||||
*/
|
||||
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)
|
||||
*/
|
||||
|
||||
@@ -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<RawFile>}
|
||||
*/
|
||||
static async resolveFile(fileLike) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
24
packages/discord.js/typings/index.d.ts
vendored
24
packages/discord.js/typings/index.d.ts
vendored
@@ -148,7 +148,7 @@ import {
|
||||
RawInviteData,
|
||||
RawInviteGuildData,
|
||||
RawInviteStageInstance,
|
||||
RawMessageAttachmentData,
|
||||
RawAttachmentData,
|
||||
RawMessageButtonInteractionData,
|
||||
RawMessageComponentInteractionData,
|
||||
RawMessageData,
|
||||
@@ -1645,7 +1645,7 @@ export class Message<Cached extends boolean = boolean> extends Base {
|
||||
|
||||
public activity: MessageActivity | null;
|
||||
public applicationId: Snowflake | null;
|
||||
public attachments: Collection<Snowflake, MessageAttachment>;
|
||||
public attachments: Collection<Snowflake, Attachment>;
|
||||
public author: User;
|
||||
public get channel(): If<Cached, GuildTextBasedChannel, TextBasedChannel>;
|
||||
public channelId: Snowflake;
|
||||
@@ -1710,8 +1710,8 @@ export class Message<Cached extends boolean = boolean> extends Base {
|
||||
public inGuild(): this is Message<true> & 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<RawFile>;
|
||||
public static resolveFile(fileLike: BufferResolvable | Stream | FileOptions | Attachment): Promise<RawFile>;
|
||||
|
||||
public makeContent(): string | undefined;
|
||||
public resolveBody(): this;
|
||||
@@ -3167,7 +3167,7 @@ export class GuildStickerManager extends CachedManager<Snowflake, Sticker, Stick
|
||||
private constructor(guild: Guild, iterable?: Iterable<RawStickerData>);
|
||||
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<Cached extends CacheType = CacheType>
|
||||
member?: CacheTypeReducer<Cached, GuildMember, APIInteractionDataResolvedGuildMember>;
|
||||
channel?: CacheTypeReducer<Cached, GuildBasedChannel, APIInteractionDataResolvedChannel>;
|
||||
role?: CacheTypeReducer<Cached, Role, APIRole>;
|
||||
attachment?: MessageAttachment;
|
||||
attachment?: Attachment;
|
||||
message?: GuildCacheMessage<Cached>;
|
||||
}
|
||||
|
||||
@@ -3915,7 +3915,7 @@ export interface CommandInteractionResolvedData<Cached extends CacheType = Cache
|
||||
roles?: Collection<Snowflake, CacheTypeReducer<Cached, Role, APIRole>>;
|
||||
channels?: Collection<Snowflake, CacheTypeReducer<Cached, AnyChannel, APIInteractionDataResolvedChannel>>;
|
||||
messages?: Collection<Snowflake, CacheTypeReducer<Cached, Message, APIMessage>>;
|
||||
attachments?: Collection<Snowflake, MessageAttachment>;
|
||||
attachments?: Collection<Snowflake, Attachment>;
|
||||
}
|
||||
|
||||
export declare const Colors: {
|
||||
@@ -4765,10 +4765,10 @@ export type MessageChannelComponentCollectorOptions<T extends MessageComponentIn
|
||||
>;
|
||||
|
||||
export interface MessageEditOptions {
|
||||
attachments?: MessageAttachment[];
|
||||
attachments?: Attachment[];
|
||||
content?: string | null;
|
||||
embeds?: (JSONEncodable<APIEmbed> | APIEmbed)[] | null;
|
||||
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[];
|
||||
files?: (FileOptions | BufferResolvable | Stream | Attachment)[];
|
||||
flags?: BitFieldResolvable<MessageFlagsString, number>;
|
||||
allowedMentions?: MessageMentionOptions;
|
||||
components?: (
|
||||
@@ -4818,10 +4818,10 @@ export interface MessageOptions {
|
||||
| APIActionRowComponent<APIMessageActionRowComponent>
|
||||
)[];
|
||||
allowedMentions?: MessageMentionOptions;
|
||||
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[];
|
||||
files?: (FileOptions | BufferResolvable | Stream | Attachment)[];
|
||||
reply?: ReplyOptions;
|
||||
stickers?: StickerResolvable[];
|
||||
attachments?: MessageAttachment[];
|
||||
attachments?: Attachment[];
|
||||
flags?: BitFieldResolvable<Extract<MessageFlagsString, 'SuppressEmbeds'>, number>;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ActionRowData<MessageActionRowComponentData>>({
|
||||
|
||||
declare const chatInputInteraction: ChatInputCommandInteraction;
|
||||
|
||||
expectType<MessageAttachment>(chatInputInteraction.options.getAttachment('attachment', true));
|
||||
expectType<MessageAttachment | null>(chatInputInteraction.options.getAttachment('attachment'));
|
||||
expectType<Attachment>(chatInputInteraction.options.getAttachment('attachment', true));
|
||||
expectType<Attachment | null>(chatInputInteraction.options.getAttachment('attachment'));
|
||||
|
||||
declare const modal: ModalBuilder;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user