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

Code before:

    const data = await this.client.rest.post(Routes.webhookPlatform(this.id, this.token, 'slack'), {
      query: makeURLSearchParams({ wait: true }),
      auth: false,
      body,
    });
    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>
   */


Review comment (suggestion):

```suggestion
  async edit({ name = this.name, avatar: newAvatar, channel: newChannel, reason }) {
```

Code after:

    const data = await this.client.rest.post(Routes.webhookPlatform(this.id, this.token, 'slack'), {
      query: makeURLSearchParams({ wait: true }),
      auth: false,
      body,
    });
    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>
   */

  /**