Repository: discordjs/discord.js
File: packages/discord.js/src/structures/Webhook.js (JavaScript)

Code before:
    });
    return data.toString() === 'ok';
  }

  /**
   * Options used to edit a {@link Webhook}.
   * @typedef {Object} WebhookEditOptions
   * @property {string} [name=this.name] The new name for the webhook
   * @property {?(BufferResolvable)} [avatar] The new avatar for the webhook
   * @property {GuildTextChannelResolvable|VoiceChannel|StageChannel|ForumChannel|MediaChannel} [channel]
   * The new channel for the webhook
   * @property {string} [reason] Reason for editing the webhook
   */

  /**
   * Edits this webhook.
   * @param {WebhookEditOptions} options Options for editing the webhook
   * @returns {Promise<Webhook>}
   */
  async edit({ name: newName, avatar: newAvatar, channel: newChannel, reason }) {
    const name = newName ?? this.name;
    let avatar = newAvatar;
    if (avatar && !(typeof avatar === 'string' && avatar.startsWith('data:'))) {
      avatar = await resolveImage(avatar);
    }
    const channel = newChannel ? (newChannel.id ?? newChannel) : undefined;
    const data = await this.client.rest.patch(Routes.webhook(this.id, channel ? undefined : this.token), {
      body: { name, avatar, channel_id: channel },
      reason,
      auth: !this.token || Boolean(channel),
    });

    this.name = data.name;
    this.avatar = data.avatar;
    this.channelId = data.channel_id;
    return this;
  }

  /**
   * Options that can be passed into fetchMessage.
   * @typedef {options} WebhookFetchMessageOptions
   * @property {boolean} [cache=true] Whether to cache the message.
   * @property {Snowflake} [threadId] The id of the thread this message belongs to.
   * <info>For interaction webhooks, this property is ignored</info>
   */

  /**
   * Gets a message that was sent by this webhook.
   * @param {Snowflake|'@original'} message The id of the message to fetch
   * @param {WebhookFetchMessageOptions} [options={}] The options to provide to fetch the message.
   * @returns {Promise<Message>} Returns the message sent by this webhook

Review comment (suggestion):

```suggestion
    const channel = newChannel?.id ?? newChannel;
```

Code after:
    });
    return data.toString() === 'ok';
  }

  /**
   * Options used to edit a {@link Webhook}.
   * @typedef {Object} WebhookEditOptions
   * @property {string} [name=this.name] The new name for the webhook
   * @property {?(BufferResolvable)} [avatar] The new avatar for the webhook
   * @property {GuildTextChannelResolvable|VoiceChannel|StageChannel|ForumChannel|MediaChannel} [channel]
   * The new channel for the webhook
   * @property {string} [reason] Reason for editing the webhook
   */

  /**
   * Edits this webhook.
   * @param {WebhookEditOptions} options Options for editing the webhook
   * @returns {Promise<Webhook>}
   */
  async edit({ name = this.name, avatar: newAvatar, channel: newChannel, reason }) {
    let avatar = newAvatar;
    if (avatar && !(typeof avatar === 'string' && avatar.startsWith('data:'))) {
      avatar = await resolveImage(avatar);
    }
    const channel = newChannel?.id ?? newChannel;
    const data = await this.client.rest.patch(Routes.webhook(this.id, channel ? undefined : this.token), {
      body: { name, avatar, channel_id: channel },
      reason,
      auth: !this.token || Boolean(channel),
    });

    this.name = data.name;
    this.avatar = data.avatar;
    this.channelId = data.channel_id;
    return this;
  }

  /**
   * Options that can be passed into fetchMessage.
   * @typedef {options} WebhookFetchMessageOptions
   * @property {boolean} [cache=true] Whether to cache the message.
   * @property {Snowflake} [threadId] The id of the thread this message belongs to.
   * <info>For interaction webhooks, this property is ignored</info>
   */

  /**
   * Gets a message that was sent by this webhook.
   * @param {Snowflake|'@original'} message The id of the message to fetch
   * @param {WebhookFetchMessageOptions} [options={}] The options to provide to fetch the message.
   * @returns {Promise<Message>} Returns the message sent by this webhook
   */