Repository: discordjs/discord.js
File: packages/builders/src/messages/Message.ts (TypeScript)

Code before:
		return this;
	}

	/**
	 * Updates the allowed mentions for this message (and creates it if it doesn't exist)
	 *
	 * @param updater - The function to update the allowed mentions with
	 */
	public updateAllowedMentions(updater: (builder: AllowedMentionsBuilder) => AllowedMentionsBuilder): this {
		updater((this.data.allowed_mentions ??= new AllowedMentionsBuilder()));
		return this;
	}

	/**
	 * Clears the allowed mentions for this message.
	 */
	public clearAllowedMentions(): this {
		this.data.allowed_mentions = undefined;
		return this;
	}

	/**
	 * Sets the message reference for this message.
	 *
	 * @param reference - The reference to set
	 */
	public setMessageReference(
		reference:
			| APIMessageReference
			| MessageReferenceBuilder
			| ((builder: MessageReferenceBuilder) => MessageReferenceBuilder),
	): this {
		this.data.message_reference = resolveBuilder(reference, MessageReferenceBuilder);
		return this;
	}

	/**
	 * Updates the message reference for this message (and creates it if it doesn't exist)
	 *
	 * @param updater - The function to update the message reference with
	 */
	public updateMessageReference(updater: (builder: MessageReferenceBuilder) => MessageReferenceBuilder): this {
		updater((this.data.message_reference ??= new MessageReferenceBuilder()));
		return this;
	}

	/**
	 * Clears the message reference for this message.
	 */
	public clearMessageReference(): this {
		this.data.message_reference = undefined;

Review comment (suggestion):
On second thought this relies on the assumption that the passed function returns the same builder it gets passed. While that *should* normally be the case we don‘t actually require it anywhere yet. If you create a new Builder inside the callback and return that it should work as intended, but wouldn’t with this change.
Same applies to all the other places this was done

Code after:
	public setEmbeds(...embeds: RestOrArray<APIEmbed | EmbedBuilder | ((builder: EmbedBuilder) => EmbedBuilder)>): this {
		return this.spliceEmbeds(0, this.embeds.length, ...normalizeArray(embeds));
	}

	/**
	 * Sets the allowed mentions for this message.
	 *
	 * @param allowedMentions - The allowed mentions to set
	 */
	public setAllowedMentions(
		allowedMentions:
			| AllowedMentionsBuilder
			| APIAllowedMentions
			| ((builder: AllowedMentionsBuilder) => AllowedMentionsBuilder),
	): this {
		this.data.allowed_mentions = resolveBuilder(allowedMentions, AllowedMentionsBuilder);
		return this;
	}

	/**
	 * Updates the allowed mentions for this message (and creates it if it doesn't exist)
	 *
	 * @param updater - The function to update the allowed mentions with
	 */
	public updateAllowedMentions(updater: (builder: AllowedMentionsBuilder) => void): this {
		updater((this.data.allowed_mentions ??= new AllowedMentionsBuilder()));
		return this;
	}

	/**
	 * Clears the allowed mentions for this message.
	 */
	public clearAllowedMentions(): this {
		this.data.allowed_mentions = undefined;
		return this;
	}

	/**
	 * Sets the message reference for this message.
	 *
	 * @param reference - The reference to set
	 */
	public setMessageReference(
		reference:
			| APIMessageReference
			| MessageReferenceBuilder
			| ((builder: MessageReferenceBuilder) => MessageReferenceBuilder),
	): this {
		this.data.message_reference = resolveBuilder(reference, MessageReferenceBuilder);
		return this;
	}