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:
MateoDeveloper
2022-04-17 03:57:38 -05:00
committed by GitHub
parent 1b2d8decb6
commit ab4c608b97
12 changed files with 42 additions and 42 deletions

View File

@@ -122,7 +122,7 @@ exports.Invite = require('./structures/Invite');
exports.InviteStageInstance = require('./structures/InviteStageInstance'); exports.InviteStageInstance = require('./structures/InviteStageInstance');
exports.InviteGuild = require('./structures/InviteGuild'); exports.InviteGuild = require('./structures/InviteGuild');
exports.Message = require('./structures/Message').Message; exports.Message = require('./structures/Message').Message;
exports.MessageAttachment = require('./structures/MessageAttachment'); exports.Attachment = require('./structures/Attachment');
exports.ModalBuilder = require('./structures/ModalBuilder'); exports.ModalBuilder = require('./structures/ModalBuilder');
exports.MessageCollector = require('./structures/MessageCollector'); exports.MessageCollector = require('./structures/MessageCollector');
exports.MessageComponentInteraction = require('./structures/MessageComponentInteraction'); exports.MessageComponentInteraction = require('./structures/MessageComponentInteraction');

View File

@@ -41,7 +41,7 @@ class GuildStickerManager extends CachedManager {
/** /**
* Creates a new custom sticker in the guild. * 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} name The name for the sticker
* @param {string} tags The Discord name of a unicode emoji representing the sticker's expression * @param {string} tags The Discord name of a unicode emoji representing the sticker's expression
* @param {GuildStickerCreateOptions} [options] Options * @param {GuildStickerCreateOptions} [options] Options

View File

@@ -3,9 +3,9 @@
const Util = require('../util/Util'); 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 {BufferResolvable|Stream} attachment The file
* @param {string} [name=null] The name of the file, if any * @param {string} [name=null] The name of the file, if any
@@ -24,7 +24,7 @@ class MessageAttachment {
/** /**
* Sets the description of this attachment. * Sets the description of this attachment.
* @param {string} description The description of the file * @param {string} description The description of the file
* @returns {MessageAttachment} This attachment * @returns {Attachment} This attachment
*/ */
setDescription(description) { setDescription(description) {
this.description = description; this.description = description;
@@ -35,7 +35,7 @@ class MessageAttachment {
* Sets the file of this attachment. * Sets the file of this attachment.
* @param {BufferResolvable|Stream} attachment The file * @param {BufferResolvable|Stream} attachment The file
* @param {string} [name=null] The name of the file, if any * @param {string} [name=null] The name of the file, if any
* @returns {MessageAttachment} This attachment * @returns {Attachment} This attachment
*/ */
setFile(attachment, name = null) { setFile(attachment, name = null) {
this.attachment = attachment; this.attachment = attachment;
@@ -46,7 +46,7 @@ class MessageAttachment {
/** /**
* Sets the name of this attachment. * Sets the name of this attachment.
* @param {string} name The name of the file * @param {string} name The name of the file
* @returns {MessageAttachment} This attachment * @returns {Attachment} This attachment
*/ */
setName(name) { setName(name) {
this.name = name; this.name = name;
@@ -56,7 +56,7 @@ class MessageAttachment {
/** /**
* Sets whether this attachment is a spoiler * Sets whether this attachment is a spoiler
* @param {boolean} [spoiler=true] Whether the attachment should be marked as 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) { setSpoiler(spoiler = true) {
if (spoiler === this.spoiler) return this; if (spoiler === this.spoiler) return this;
@@ -163,7 +163,7 @@ class MessageAttachment {
} }
} }
module.exports = MessageAttachment; module.exports = Attachment;
/** /**
* @external APIAttachment * @external APIAttachment

View File

@@ -1,9 +1,9 @@
'use strict'; 'use strict';
const { Collection } = require('@discordjs/collection'); const { Collection } = require('@discordjs/collection');
const Attachment = require('./Attachment');
const Interaction = require('./Interaction'); const Interaction = require('./Interaction');
const InteractionWebhook = require('./InteractionWebhook'); const InteractionWebhook = require('./InteractionWebhook');
const MessageAttachment = require('./MessageAttachment');
const InteractionResponses = require('./interfaces/InteractionResponses'); 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, Role|APIRole>} [roles] The resolved roles
* @property {Collection<Snowflake, Channel|APIChannel>} [channels] The resolved channels * @property {Collection<Snowflake, Channel|APIChannel>} [channels] The resolved channels
* @property {Collection<Snowflake, Message|APIMessage>} [messages] The resolved messages * @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) { if (attachments) {
result.attachments = new Collection(); result.attachments = new Collection();
for (const attachment of Object.values(attachments)) { 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); result.attachments.set(attachment.id, patched);
} }
} }
@@ -156,7 +156,7 @@ class CommandInteraction extends Interaction {
* @property {GuildMember|APIGuildMember} [member] The resolved member * @property {GuildMember|APIGuildMember} [member] The resolved member
* @property {GuildChannel|ThreadChannel|APIChannel} [channel] The resolved channel * @property {GuildChannel|ThreadChannel|APIChannel} [channel] The resolved channel
* @property {Role|APIRole} [role] The resolved role * @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; if (role) result.role = this.guild?.roles._add(role) ?? role;
const attachment = resolved.attachments?.[option.value]; 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; return result;

View File

@@ -220,7 +220,7 @@ class CommandInteractionOptionResolver {
* Gets an attachment option. * Gets an attachment option.
* @param {string} name The name of the option. * @param {string} name The name of the option.
* @param {boolean} [required=false] Whether to throw an error if the option is not found. * @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) { getAttachment(name, required = false) {
const option = this._getTypedOption(name, ApplicationCommandOptionType.Attachment, ['attachment'], required); const option = this._getTypedOption(name, ApplicationCommandOptionType.Attachment, ['attachment'], required);

View File

@@ -9,11 +9,11 @@ const {
MessageFlags, MessageFlags,
PermissionFlagsBits, PermissionFlagsBits,
} = require('discord-api-types/v10'); } = require('discord-api-types/v10');
const Attachment = require('./Attachment');
const Base = require('./Base'); const Base = require('./Base');
const ClientApplication = require('./ClientApplication'); const ClientApplication = require('./ClientApplication');
const Embed = require('./Embed'); const Embed = require('./Embed');
const InteractionCollector = require('./InteractionCollector'); const InteractionCollector = require('./InteractionCollector');
const MessageAttachment = require('./MessageAttachment');
const Mentions = require('./MessageMentions'); const Mentions = require('./MessageMentions');
const MessagePayload = require('./MessagePayload'); const MessagePayload = require('./MessagePayload');
const ReactionCollector = require('./ReactionCollector'); const ReactionCollector = require('./ReactionCollector');
@@ -154,12 +154,12 @@ class Message extends Base {
if ('attachments' in data) { if ('attachments' in data) {
/** /**
* A collection of attachments in the message - e.g. Pictures - mapped by their ids * 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(); this.attachments = new Collection();
if (data.attachments) { if (data.attachments) {
for (const attachment of 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 { } else {
@@ -642,9 +642,9 @@ class Message extends Base {
* @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content * @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content
* @property {MessageFlags} [flags] Which flags to set for the message. * @property {MessageFlags} [flags] Which flags to set for the message.
* Only `MessageFlags.SuppressEmbeds` can be edited. * 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 * 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] * @property {ActionRow[]|ActionRowOptions[]} [components]
* Action rows containing interactive components for the message (buttons, select menus) * Action rows containing interactive components for the message (buttons, select menus)
*/ */

View File

@@ -224,7 +224,7 @@ class MessagePayload {
/** /**
* Resolves a single file into an object sendable to the API. * 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>} * @returns {Promise<RawFile>}
*/ */
static async resolveFile(fileLike) { static async resolveFile(fileLike) {

View File

@@ -132,9 +132,9 @@ class Webhook {
* @typedef {Object} WebhookEditMessageOptions * @typedef {Object} WebhookEditMessageOptions
* @property {Embed[]|APIEmbed[]} [embeds] See {@link WebhookMessageOptions#embeds} * @property {Embed[]|APIEmbed[]} [embeds] See {@link WebhookMessageOptions#embeds}
* @property {string} [content] See {@link BaseMessageOptions#content} * @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 {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] * @property {ActionRow[]|ActionRowOptions[]} [components]
* Action rows containing interactive components for the message (buttons, select menus) * Action rows containing interactive components for the message (buttons, select menus)
* @property {Snowflake} [threadId] The id of the thread this message belongs to * @property {Snowflake} [threadId] The id of the thread this message belongs to

View File

@@ -61,10 +61,10 @@ class TextBasedChannel {
* (see [here](https://discord.com/developers/docs/resources/channel#embed-object) for more details) * (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 * @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) * (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] * @property {ActionRow[]|ActionRowOptions[]} [components]
* Action rows containing interactive components for the message (buttons, select menus) * 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
*/ */
/** /**

View File

@@ -148,7 +148,7 @@ import {
RawInviteData, RawInviteData,
RawInviteGuildData, RawInviteGuildData,
RawInviteStageInstance, RawInviteStageInstance,
RawMessageAttachmentData, RawAttachmentData,
RawMessageButtonInteractionData, RawMessageButtonInteractionData,
RawMessageComponentInteractionData, RawMessageComponentInteractionData,
RawMessageData, RawMessageData,
@@ -1645,7 +1645,7 @@ export class Message<Cached extends boolean = boolean> extends Base {
public activity: MessageActivity | null; public activity: MessageActivity | null;
public applicationId: Snowflake | null; public applicationId: Snowflake | null;
public attachments: Collection<Snowflake, MessageAttachment>; public attachments: Collection<Snowflake, Attachment>;
public author: User; public author: User;
public get channel(): If<Cached, GuildTextBasedChannel, TextBasedChannel>; public get channel(): If<Cached, GuildTextBasedChannel, TextBasedChannel>;
public channelId: Snowflake; public channelId: Snowflake;
@@ -1710,8 +1710,8 @@ export class Message<Cached extends boolean = boolean> extends Base {
public inGuild(): this is Message<true> & this; public inGuild(): this is Message<true> & this;
} }
export class MessageAttachment { export class Attachment {
public constructor(attachment: BufferResolvable | Stream, name?: string, data?: RawMessageAttachmentData); public constructor(attachment: BufferResolvable | Stream, name?: string, data?: RawAttachmentData);
public attachment: BufferResolvable | Stream; public attachment: BufferResolvable | Stream;
public contentType: string | null; public contentType: string | null;
@@ -1847,7 +1847,7 @@ export class MessagePayload {
options: string | MessageOptions | WebhookMessageOptions, options: string | MessageOptions | WebhookMessageOptions,
extra?: MessageOptions | WebhookMessageOptions, extra?: MessageOptions | WebhookMessageOptions,
): MessagePayload; ): 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 makeContent(): string | undefined;
public resolveBody(): this; public resolveBody(): this;
@@ -3167,7 +3167,7 @@ export class GuildStickerManager extends CachedManager<Snowflake, Sticker, Stick
private constructor(guild: Guild, iterable?: Iterable<RawStickerData>); private constructor(guild: Guild, iterable?: Iterable<RawStickerData>);
public guild: Guild; public guild: Guild;
public create( public create(
file: BufferResolvable | Stream | FileOptions | MessageAttachment, file: BufferResolvable | Stream | FileOptions | Attachment,
name: string, name: string,
tags: string, tags: string,
options?: GuildStickerCreateOptions, options?: GuildStickerCreateOptions,
@@ -3905,7 +3905,7 @@ export interface CommandInteractionOption<Cached extends CacheType = CacheType>
member?: CacheTypeReducer<Cached, GuildMember, APIInteractionDataResolvedGuildMember>; member?: CacheTypeReducer<Cached, GuildMember, APIInteractionDataResolvedGuildMember>;
channel?: CacheTypeReducer<Cached, GuildBasedChannel, APIInteractionDataResolvedChannel>; channel?: CacheTypeReducer<Cached, GuildBasedChannel, APIInteractionDataResolvedChannel>;
role?: CacheTypeReducer<Cached, Role, APIRole>; role?: CacheTypeReducer<Cached, Role, APIRole>;
attachment?: MessageAttachment; attachment?: Attachment;
message?: GuildCacheMessage<Cached>; message?: GuildCacheMessage<Cached>;
} }
@@ -3915,7 +3915,7 @@ export interface CommandInteractionResolvedData<Cached extends CacheType = Cache
roles?: Collection<Snowflake, CacheTypeReducer<Cached, Role, APIRole>>; roles?: Collection<Snowflake, CacheTypeReducer<Cached, Role, APIRole>>;
channels?: Collection<Snowflake, CacheTypeReducer<Cached, AnyChannel, APIInteractionDataResolvedChannel>>; channels?: Collection<Snowflake, CacheTypeReducer<Cached, AnyChannel, APIInteractionDataResolvedChannel>>;
messages?: Collection<Snowflake, CacheTypeReducer<Cached, Message, APIMessage>>; messages?: Collection<Snowflake, CacheTypeReducer<Cached, Message, APIMessage>>;
attachments?: Collection<Snowflake, MessageAttachment>; attachments?: Collection<Snowflake, Attachment>;
} }
export declare const Colors: { export declare const Colors: {
@@ -4765,10 +4765,10 @@ export type MessageChannelComponentCollectorOptions<T extends MessageComponentIn
>; >;
export interface MessageEditOptions { export interface MessageEditOptions {
attachments?: MessageAttachment[]; attachments?: Attachment[];
content?: string | null; content?: string | null;
embeds?: (JSONEncodable<APIEmbed> | APIEmbed)[] | null; embeds?: (JSONEncodable<APIEmbed> | APIEmbed)[] | null;
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[]; files?: (FileOptions | BufferResolvable | Stream | Attachment)[];
flags?: BitFieldResolvable<MessageFlagsString, number>; flags?: BitFieldResolvable<MessageFlagsString, number>;
allowedMentions?: MessageMentionOptions; allowedMentions?: MessageMentionOptions;
components?: ( components?: (
@@ -4818,10 +4818,10 @@ export interface MessageOptions {
| APIActionRowComponent<APIMessageActionRowComponent> | APIActionRowComponent<APIMessageActionRowComponent>
)[]; )[];
allowedMentions?: MessageMentionOptions; allowedMentions?: MessageMentionOptions;
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[]; files?: (FileOptions | BufferResolvable | Stream | Attachment)[];
reply?: ReplyOptions; reply?: ReplyOptions;
stickers?: StickerResolvable[]; stickers?: StickerResolvable[];
attachments?: MessageAttachment[]; attachments?: Attachment[];
flags?: BitFieldResolvable<Extract<MessageFlagsString, 'SuppressEmbeds'>, number>; flags?: BitFieldResolvable<Extract<MessageFlagsString, 'SuppressEmbeds'>, number>;
} }

View File

@@ -57,7 +57,7 @@ import {
Interaction, Interaction,
InteractionCollector, InteractionCollector,
Message, Message,
MessageAttachment, Attachment,
MessageCollector, MessageCollector,
MessageComponentInteraction, MessageComponentInteraction,
MessageReaction, MessageReaction,
@@ -584,7 +584,7 @@ client.on('messageCreate', async message => {
assertIsMessage(channel.send({})); assertIsMessage(channel.send({}));
assertIsMessage(channel.send({ embeds: [] })); assertIsMessage(channel.send({ embeds: [] }));
const attachment = new MessageAttachment('file.png'); const attachment = new Attachment('file.png');
const embed = new EmbedBuilder(); const embed = new EmbedBuilder();
assertIsMessage(channel.send({ files: [attachment] })); assertIsMessage(channel.send({ files: [attachment] }));
assertIsMessage(channel.send({ embeds: [embed] })); assertIsMessage(channel.send({ embeds: [embed] }));
@@ -1456,8 +1456,8 @@ expectNotAssignable<ActionRowData<MessageActionRowComponentData>>({
declare const chatInputInteraction: ChatInputCommandInteraction; declare const chatInputInteraction: ChatInputCommandInteraction;
expectType<MessageAttachment>(chatInputInteraction.options.getAttachment('attachment', true)); expectType<Attachment>(chatInputInteraction.options.getAttachment('attachment', true));
expectType<MessageAttachment | null>(chatInputInteraction.options.getAttachment('attachment')); expectType<Attachment | null>(chatInputInteraction.options.getAttachment('attachment'));
declare const modal: ModalBuilder; declare const modal: ModalBuilder;

View File

@@ -152,7 +152,7 @@ export type RawInviteStageInstance = APIInviteStageInstance;
export type RawMessageData = APIMessage; export type RawMessageData = APIMessage;
export type RawPartialMessageData = GatewayMessageUpdateDispatchData; export type RawPartialMessageData = GatewayMessageUpdateDispatchData;
export type RawMessageAttachmentData = APIAttachment; export type RawAttachmentData = APIAttachment;
export type RawMessagePayloadData = export type RawMessagePayloadData =
| RESTPostAPIChannelMessageJSONBody | RESTPostAPIChannelMessageJSONBody