Repository: discordjs/discord.js
File: packages/discord.js/src/managers/MessageManager.js (JavaScript)

Code before:
   * @property {Array<Attachment|MessageEditAttachmentData>} [attachments] An array of attachments to keep.
   * All attachments will be kept if omitted
   * @property {MessageFlags} [flags] Which flags to set for the message
   * <info>Only the {@link MessageFlags.SuppressEmbeds} flag can be modified.</info>
   */

  /**
   * Edits a message, even if it's not cached.
   *
   * @param {MessageResolvable} message The message to edit
   * @param {string|MessageEditOptions|MessagePayload|FileBodyEncodable<RESTPatchAPIChannelMessageJSONBody>|JSONEncodable<RESTPatchAPIChannelMessageJSONBody>} options The options to edit the message
   * @returns {Promise<Message>}
   */
  async edit(message, options) {
    const messageId = this.resolveId(message);
    if (!messageId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');

    let payload;
    if (options instanceof MessagePayload) {
      payload = await options.resolveBody().resolveFiles();
    } else if (isFileBodyEncodable(options)) {
      payload = options.toFileBody();
    } else if (isJSONEncodable(options)) {
      payload = { body: options.toJSON(), files: [] };
    } else {
      payload = await MessagePayload.create(this, options).resolveBody().resolveFiles();
    }

    const data = await this.client.rest.patch(Routes.channelMessage(this.channel.id, messageId), payload);

    const existing = this.cache.get(messageId);
    if (existing) {
      const clone = existing._clone();
      clone._patch(data);
      return clone;
    }

    return this._add(data);
  }

  /**
   * Pins a message to the channel's pinned messages, even if it's not cached.
   *
   * @param {MessageResolvable} message The message to pin
   * @param {string} [reason] Reason for pinning
   * @returns {Promise<void>}
   */
  async pin(message, reason) {
    const messageId = this.resolveId(message);
    if (!messageId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');


Review comment (suggestion):
Unless the new code is correct

```suggestion
      payload = await MessagePayload.create(message instanceof Message ? message : this, options).resolveBody().resolveFiles();
```

Code after:
   * @property {Array<Attachment|MessageEditAttachmentData>} [attachments] An array of attachments to keep.
   * All attachments will be kept if omitted
   * @property {MessageFlags} [flags] Which flags to set for the message
   * <info>Only the {@link MessageFlags.SuppressEmbeds} flag can be modified.</info>
   */

  /**
   * Edits a message, even if it's not cached.
   *
   * @param {MessageResolvable} message The message to edit
   * @param {string|MessageEditOptions|MessagePayload|FileBodyEncodable<RESTPatchAPIChannelMessageJSONBody>|JSONEncodable<RESTPatchAPIChannelMessageJSONBody>} options The options to edit the message
   * @returns {Promise<Message>}
   */
  async edit(message, options) {
    const messageId = this.resolveId(message);
    if (!messageId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');

    let payload;
    if (options instanceof MessagePayload) {
      payload = await options.resolveBody().resolveFiles();
    } else if (isFileBodyEncodable(options)) {
      payload = options.toFileBody();
    } else if (isJSONEncodable(options)) {
      payload = { body: options.toJSON() };
    } else {
      payload = await MessagePayload.create(message instanceof Message ? message : this, options)
        .resolveBody()
        .resolveFiles();
    }

    const data = await this.client.rest.patch(Routes.channelMessage(this.channel.id, messageId), payload);

    const existing = this.cache.get(messageId);
    if (existing) {
      const clone = existing._clone();
      clone._patch(data);
      return clone;
    }

    return this._add(data);
  }

  /**
   * Pins a message to the channel's pinned messages, even if it's not cached.
   *
   * @param {MessageResolvable} message The message to pin
   * @param {string} [reason] Reason for pinning
   * @returns {Promise<void>}
   */
  async pin(message, reason) {
    const messageId = this.resolveId(message);