One special entity in a text message (like mention, hashtag, URL, etc.)

Constructors

Properties

Accessors

Methods

Constructors

Properties

_text?: string

Accessors

  • get kind(): | "url"
    | "bold"
    | "email"
    | "code"
    | "spoiler"
    | "emoji"
    | "hashtag"
    | "mention"
    | "cashtag"
    | "bot_command"
    | "phone_number"
    | "italic"
    | "underline"
    | "strikethrough"
    | "bank_card"
    | "unknown"
    | "blockquote"
    | "pre"
    | "text_link"
    | "text_mention"
  • Kind of the entity (see MessageEntityParams)

    Returns
        | "url"
        | "bold"
        | "email"
        | "code"
        | "spoiler"
        | "emoji"
        | "hashtag"
        | "mention"
        | "cashtag"
        | "bot_command"
        | "phone_number"
        | "italic"
        | "underline"
        | "strikethrough"
        | "bank_card"
        | "unknown"
        | "blockquote"
        | "pre"
        | "text_link"
        | "text_mention"

  • get length(): number
  • Length of the entity in UTF-16 code units.

    Since JS strings are UTF-16, you can use this as-is

    Returns number

  • get offset(): number
  • Offset in UTF-16 code units to the start of the entity.

    Since JS strings are UTF-16, you can use this as-is

    Returns number

  • get text(): string
  • Text contained in this entity.

    Note: This does not take into account that entities may overlap, and is only useful for simple cases.

    Returns string

Methods

  • Checks if this entity is of the given type, and adjusts the type accordingly.

    Type Parameters

    • const T extends
          | "url"
          | "bold"
          | "email"
          | "code"
          | "spoiler"
          | "emoji"
          | "hashtag"
          | "mention"
          | "cashtag"
          | "bot_command"
          | "phone_number"
          | "italic"
          | "underline"
          | "strikethrough"
          | "bank_card"
          | "unknown"
          | "blockquote"
          | "pre"
          | "text_link"
          | "text_mention"

    Parameters

    • kind: T

    Returns this is MessageEntity & {
        kind: T;
        params:
            | Extract<
                {
                    kind: | "url"
                    | "bold"
                    | "email"
                    | "code"
                    | "spoiler"
                    | "hashtag"
                    | "mention"
                    | "cashtag"
                    | "bot_command"
                    | "phone_number"
                    | "italic"
                    | "underline"
                    | "strikethrough"
                    | "bank_card"
                    | "unknown";
                },
                { kind: T },
            >
            | Extract<{ collapsible: boolean; kind: "blockquote" }, { kind: T }>
            | Extract<{ kind: "pre"; language?: string }, { kind: T }>
            | Extract<{ kind: "text_link"; url: string }, { kind: T }>
            | Extract<{ kind: "text_mention"; userId: number }, { kind: T }>
            | Extract<{ emojiId: Long; kind: "emoji" }, { kind: T }>;
    }