import type { APITextDisplayComponent, Snowflake } from "discord.js"; import { ComponentType, TextDisplayBuilder } from "discord.js"; /** * A class for creating a text display component */ export class V2TextDisplay { private id?: number; private content: Snowflake; private readonly type = ComponentType.TextDisplay; /** * Create a new text display component * @param content - The text content to display */ constructor(content: Snowflake) { this.content = content; } /** * Set the ID of the text display * @param id - The numeric ID * @returns The text display instance */ setId(id: number) { this.id = id; return this; } /** * Set the content of the text display * @param content - The text content to display (supports markdown) * @returns The text display instance */ setContent(content: Snowflake) { this.content = content; return this; } /** * Convert the text display to a JSON object * @returns The JSON representation of the text display */ toJSON(): APITextDisplayComponent { return { type: this.type, content: this.content, ...(this.id !== undefined && { id: this.id }), }; } } /** * Helper function to create a text display component * @param content - The text content to display (supports markdown) * @param id - Optional numeric ID for the component * @returns A TextDisplayBuilder instance ready to use in sections * * @example * ```typescript * // Simple text * const text = makeTextDisplay("Hello World"); * * // With markdown * const title = makeTextDisplay("**Bold Title**"); * * // With ID * const text = makeTextDisplay("Content", 123); * ``` */ export function makeTextDisplay( content: Snowflake, id?: number, ): TextDisplayBuilder { const builder = new TextDisplayBuilder().setContent(content); if (id !== undefined) builder.setId(id); return builder; }