#How can I detect if someone sent a message?

5 messages · Page 1 of 1 (latest)

lunar crown
#

I don't know how to detect chat messages and get the contents I was trying (this code dosnt work for some reason)```world.events.beforeChat.subscribe(async (eventData) => {
const player = eventData.sender;
if (!player.hasTag('Admin')) return;
switch (eventData.message) {
case '!gmc':
eventData.cancel = true;
await player.runCommandAsync('gamemode c');
break;
case '!gms':
eventData.cancel = true;
await player.runCommandAsync('gamemode s');
break;
default: break;
}
});

leaden hamletBOT
#
Thanks for asking your question!

Once you have finished, please close your thread.

proven swift
#

@lunar crown You are using an async function. The event data is wiped the instant after the function is executed, and you are only preserving the sender's information but not the message itself.

#

I would change line 2 to be const {sender, message} = eventData, then reference the sender and message variables

lunar crown
#

it still wont work because it wont do anything if i type !gmc or !gms