#how to make commands with a prefix like "//"
1 messages · Page 1 of 1 (latest)
Can you detect chat?
From bedrock 1.17.30 stable and upper we are now able to read/modify/cancel the in-game chat with Gametest-API so custom commands are possible!
If you're completely new, read wiki
Vanilla Usage
Read the link I send
It has an example
It just an example, of course. You just have to explore scripting
Read documentation
Get the player name by using .name
Look at wiki, it start with !
You just simply replaced it with //
That's why I'm telling you to read.
import { world } from '@minecraft/server'
world.beforeEvents.chatSend.subscribe((data) => {
const prefix = '+';
const player = data.sender;
const message = data.message.toLowerCase();
const args = message.slice(prefix.length).split(new RegExp(/\s+/g));
const cmd = args.shift();
if (!message.startsWith(prefix)) return;
data.cancel = true;
switch (cmd) {
case 'gmc':
player.runCommandAsync('gamemode c')
break;
case 'gms':
player.runCommandAsync('gamemode s')
break;
default:
player.sendMessage('Invalid cmd!')
break;
}
})```
Is that what you wanted?