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

Code before:
    if (this.body) return this;
    const isInteraction = this.isInteraction;
    const isWebhook = this.isWebhook;

    const content = this.makeContent();
    const tts = Boolean(this.options.tts);

    let nonce;
    if (this.options.nonce !== undefined) {
      nonce = this.options.nonce;
      if (typeof nonce === 'number' ? !Number.isInteger(nonce) : typeof nonce !== 'string') {
        throw new DiscordjsRangeError(ErrorCodes.MessageNonceType);
      }
    }

    const enforce_nonce = Boolean(this.options.enforceNonce);

    /**
     * If `nonce` isn't provided, generate one & set `enforceNonce`
     * Unless `enforceNonce` is explicitly set to `false`(not just falsy)
     */
    if (nonce === undefined) {
      if (this.options.enforceNonce !== false && this.client.options.enforceNonce) {
        this.options.nonce = DiscordSnowflake.generate().toString();
        this.options.enforceNonce = true;
      } else if (enforce_nonce) {
        throw new DiscordjsError(ErrorCodes.MessageNonceRequired);
      }
    }

    const components = this.options.components?.map(component =>
      (isJSONEncodable(component) ? component : new ActionRowBuilder(component)).toJSON(),
    );

    let username;
    let avatarURL;
    let threadName;
    let appliedTags;
    if (isWebhook) {
      username = this.options.username ?? this.target.name;
      if (this.options.avatarURL) avatarURL = this.options.avatarURL;
      if (this.options.threadName) threadName = this.options.threadName;
      if (this.options.appliedTags) appliedTags = this.options.appliedTags;
    }

    let flags;
    if (
      this.options.flags !== undefined ||
      (this.isMessage && this.options.reply === undefined) ||
      this.isMessageManager
    ) {

Review comment (suggestion):
IMO we should just get rid of this[^1] and automatically generate a nonce if none is passed when `enforceNonce` is set to `true`.
Probably results in better DX and simplifies the logic a bit 

[^1]: meaning we stop throwing the error and deprecate the error code

Code after:
    if (this.body) return this;
    const isInteraction = this.isInteraction;
    const isWebhook = this.isWebhook;

    const content = this.makeContent();
    const tts = Boolean(this.options.tts);

    let nonce;
    if (this.options.nonce !== undefined) {
      nonce = this.options.nonce;
      if (typeof nonce === 'number' ? !Number.isInteger(nonce) : typeof nonce !== 'string') {
        throw new DiscordjsRangeError(ErrorCodes.MessageNonceType);
      }
    }

    let enforce_nonce = Boolean(this.options.enforceNonce);

    // If `nonce` isn't provided, generate one & set `enforceNonce`
    // Unless `enforceNonce` is explicitly set to `false`(not just falsy)
    if (nonce === undefined) {
      if (this.options.enforceNonce !== false && this.client.options.enforceNonce) {
        nonce = DiscordSnowflake.generate().toString();
        enforce_nonce = true;
      } else if (enforce_nonce) {
        throw new DiscordjsError(ErrorCodes.MessageNonceRequired);
      }
    }

    const components = this.options.components?.map(component =>
      (isJSONEncodable(component) ? component : new ActionRowBuilder(component)).toJSON(),
    );

    let username;
    let avatarURL;
    let threadName;
    let appliedTags;
    if (isWebhook) {
      username = this.options.username ?? this.target.name;
      if (this.options.avatarURL) avatarURL = this.options.avatarURL;
      if (this.options.threadName) threadName = this.options.threadName;
      if (this.options.appliedTags) appliedTags = this.options.appliedTags;
    }

    let flags;
    if (
      this.options.flags !== undefined ||
      (this.isMessage && this.options.reply === undefined) ||
      this.isMessageManager
    ) {
      flags =
        // eslint-disable-next-line eqeqeq