Skip to content

chat

Message

Python
Message(
    data: Union[str, Dict[str, Any], List[Any]],
    to_json: bool = False,
)

A class to handle Minecraft chat messages with full formatting and event support.

create classmethod

Python
create(
    data: Union[str, Dict[str, Any], List[Any]],
) -> Message

Factory method to create a Message instance.

PARAMETER DESCRIPTION
data

The message data to parse. Can be a string, dictionary (JSON component), or list of components.

TYPE: Union[str, Dict[str, Any], List[Any]]

RETURNS DESCRIPTION
Message

A new Message instance containing the parsed components.

to_formatted_string

Python
to_formatted_string() -> str

Convert all components to formatted string with Minecraft codes.

RETURNS DESCRIPTION
str

The formatted message string with Minecraft formatting codes (e.g., §a for green) and event markers.

to_plain_text

Python
to_plain_text() -> str

Convert all components to plain text without formatting.

RETURNS DESCRIPTION
str

The message content without any formatting or style information.

get_click_commands

Python
get_click_commands() -> List[str]

Get all click commands from all components.

RETURNS DESCRIPTION
List[str]

A list of all command strings from click events of type 'run_command' or 'suggest_command'.

get_click_events

Python
get_click_events() -> List[MessageEvent]

Get all click events from the message.

RETURNS DESCRIPTION
List[MessageEvent]

A list of all MessageEvent objects representing click actions in the message.

get_hover_events

Python
get_hover_events() -> List[MessageEvent]

Get all hover events from the message.

RETURNS DESCRIPTION
List[MessageEvent]

A list of all MessageEvent objects representing hover actions in the message.

get_components_count

Python
get_components_count() -> int

Get the total number of components in the message.


MessageEvent

Python
MessageEvent(
    action: str, value: Union[str, Dict[str, Any]]
)

Represents a click or hover event in a chat message.

action property

Python
action: str

Get the event action type.

RETURNS DESCRIPTION
str

The action type of this event (e.g., 'open_url', 'run_command').

value property

Python
value: Union[str, Dict[str, Any]]

Get the event value.

RETURNS DESCRIPTION
Union[str, Dict[str, Any]]

The value associated with this event. Could be a string (for commands/URLs) or a dictionary (for complex hover events).