Manages callbacks that are connected to chat messages being sent.

Example

chatSendEvent.ts

import { world, ChatSendAfterEvent } from "@minecraft/server";

// Subscribe to the blockExplode event
world.afterEvents.chatSend.subscribe((event: ChatSendAfterEvent) => {
const { sender, message } = event;
console.log(`${sender.name}: ${message}`);
});

Hierarchy

  • ChatSendAfterEventSignal

Constructors

Methods

Constructors

Methods

  • Parameters

    Returns ((arg) => void)

      • (arg): void
      • Parameters

        Returns void

        Remarks

        Adds a callback that will be called when new chat messages are sent.

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        Example

        custom_command.js

        const chatCallback = World.beforeEvents.chatSend.subscribe((eventData) => {
        if (eventData.message.includes("cancel")) {
        // Cancel event if the message contains "cancel"
        eventData.canceled = true;
        } else {
        // Modify chat message being sent
        eventData.message = `Modified '${eventData.message}'`;
        }
        });

    Remarks

    Adds a callback that will be called when new chat messages are sent.

    This function can't be called in read-only mode.

    This function can be called in early-execution mode.

    Example

    custom_command.js

    const chatCallback = World.beforeEvents.chatSend.subscribe((eventData) => {
    if (eventData.message.includes("cancel")) {
    // Cancel event if the message contains "cancel"
    eventData.canceled = true;
    } else {
    // Modify chat message being sent
    eventData.message = `Modified '${eventData.message}'`;
    }
    });

  • Parameters

    Returns void

    Remarks

    Removes a callback from being called when new chat messages are sent.

    This function can't be called in read-only mode.

    This function can be called in early-execution mode.