#Befor echta event not working

1 messages · Page 1 of 1 (latest)

desert radish
#

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

// Map color tags to Minecraft chat color codes
const colorCodes = {
red: "c",
orange: "6",
yellow: "e",
green: "a",
blue: "9",
cyan: "b",
purple: "5",
pink: "d"
};

// Subscribe to the chat send event
world.beforeEvents.chatSend.subscribe((event) => {
const player = event.sender;
const message = event.message;

// Default color
let colorCode = "f"; // white

// Check player tags for color
const tags = player.getTags();
for (const tag of tags) {
    if (tag.startsWith("color:")) {
        const colorName = tag.replace("color:", "").toLowerCase();
        colorCode = colorCodes[colorName] || "f"; // fallback to white
        break;
    }
}

// Format chat message: color + player name + message
const formattedMessage = `§${colorCode}${player.name} §f: ${message}`;

// Send formatted message
world.sendMessage(formattedMessage);

// Cancel original chat message
event.cancel = true;

});
thats my code, but mc keeps showing me the error
[Scripting][error]-TypeError: cannot read property 'subscribe' of undefined at <anonymous> (chat-ranks/index.js:16)

[Scripting][error]-Plugin [Chat Ranks BP - 1.0.0] - [main.js] ran with error: [TypeError: cannot read property 'subscribe' of undefined at <anonymous> (chat-ranks/index.js:16)
]

#

im loosing my shi rn cause of how stressful its been to figure out 😭

scarlet mulch
#

@desert radish are you using the beta script api?