For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /server/classes/ChatSendBeforeEventSignal.md.

Class: ChatSendBeforeEventSignal experimental

event

Beta

管理与聊天消息发送前触发的事件相关的回调。

Manages callbacks that are connected to an event that fires before chat messages are sent.

Example

customCommand.ts

import { world, DimensionLocation } from '@minecraft/server';

function customCommand(targetLocation: DimensionLocation) {
  const chatCallback = world.beforeEvents.chatSend.subscribe(eventData => {
    if (eventData.message.includes('cancel')) {
      // Cancel event if the message contains "cancel"
      eventData.cancel = true;
    } else {
      const args = eventData.message.split(' ');

      if (args.length > 0) {
        switch (args[0].toLowerCase()) {
          case 'echo':
            // Send a modified version of chat message
            world.sendMessage(`Echo '${eventData.message.substring(4).trim()}'`);
            break;
          case 'help':
            world.sendMessage(`Available commands: echo <message>`);
            break;
        }
      }
    }
  });
}

Methods

subscribe()

subscribe(callback): (arg0) => void

World Mutation Early Execution Beta

Parameters

callback

(arg0) => void

Tip

此闭包以受限执行权限被调用。

Tip

This closure is called with restricted-execution privilege.

Returns

Tip

以受限执行权限被调用的闭包。

Tip

Closure that is called with restricted-execution privilege.

(arg0) => void

Remarks

添加一个回调,将在新的聊天消息发送之前被调用。

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


unsubscribe()

unsubscribe(callback): void

World Mutation Early Execution Beta

Parameters

callback

(arg0) => void

Tip

此闭包以受限执行权限被调用。

Tip

This closure is called with restricted-execution privilege.

Returns

void

Remarks

移除一个回调,使其在新的聊天消息发送之前不再被调用。

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

同领域相关