Beta
Manages callbacks that are connected to an event that fires before chat messages are sent.
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; } } } });} Copy
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; } } } });}
import { world } from "@minecraft/server";// Subscribe to the blockExplode eventworld.beforeEvents.chatSend.subscribe((event) => { const { sender, message } = event; console.log(`${sender.name}: ${message}`); event.cancel = true; // Cancel message to be sent if needed.}); Copy
import { world } from "@minecraft/server";// Subscribe to the blockExplode eventworld.beforeEvents.chatSend.subscribe((event) => { const { sender, message } = event; console.log(`${sender.name}: ${message}`); event.cancel = true; // Cancel message to be sent if needed.});
Adds a callback that will be called before new chat messages are sent.
This function can't be called in read-only mode.
This function can be called in early-execution mode.
Removes a callback from being called before new chat messages are sent.
Manages callbacks that are connected to an event that fires before chat messages are sent.
Example: customCommand.ts
Example: chatSendEvent.ts