From 5001fe29bbe1231afdaa04c5f54207ce2232b7f6 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Mon, 31 May 2021 18:43:28 +0200 Subject: [PATCH] feat(Message): allow editing files into messages --- src/managers/MessageManager.js | 6 ++++-- src/structures/Message.js | 4 +++- typings/index.d.ts | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index 6e99fa3ba5a8..199b8e0e583d 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -124,8 +124,10 @@ class MessageManager extends BaseManager { message = this.resolveID(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); - const { data } = (options instanceof APIMessage ? options : APIMessage.create(this, options)).resolveData(); - const d = await this.client.api.channels[this.channel.id].messages[message].patch({ data }); + const { data, files } = await (options instanceof APIMessage ? options : APIMessage.create(this, options)) + .resolveData() + .resolveFiles(); + const d = await this.client.api.channels[this.channel.id].messages[message].patch({ data, files }); if (this.cache.has(message)) { const clone = this.cache.get(message)._clone(); diff --git a/src/structures/Message.js b/src/structures/Message.js index a852ceb7dfa1..3964a8dd47b1 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -479,7 +479,9 @@ class Message extends Base { * @property {string|boolean} [code] Language for optional codeblock formatting to apply * @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content * @property {MessageFlags} [flags] Which flags to set for the message. Only `SUPPRESS_EMBEDS` can be edited. - * @property {MessageAttachment[]} [attachments] The new attachments of the message (can only be removed, not added) + * @property {MessageAttachment[]} [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 */ /** diff --git a/typings/index.d.ts b/typings/index.d.ts index a6450c6b1040..dd6afb8f51fa 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3184,12 +3184,13 @@ declare module 'discord.js' { } interface MessageEditOptions { + attachments?: MessageAttachment[]; content?: StringResolvable; embed?: MessageEmbed | MessageEmbedOptions | null; code?: string | boolean; + files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[]; flags?: BitFieldResolvable; allowedMentions?: MessageMentionOptions; - attachments?: MessageAttachment[]; } interface MessageEmbedAuthor {