Skip to content
job-gut edited this page Feb 8, 2023 · 6 revisions

Register commands

import { command } from "bdsx/command";
import { CommandRawText } from "bdsx/bds/command";
command.register('echo', 'repeat text').overload((param, origin, output)=>{
    console.log(param.rawtext.text);
}, { rawtext:CommandRawText });

Register commands with a permission level

import { command } from "bdsx/command";
import { CommandRawText } from "bdsx/bds/command";
command.register('echo', 'repeat text', CommandPermissionLevel.Operator).overload((param, origin, output) => { //makes it so only people with Operator can use and see the command
     console.log(param.rawtext.text);
}, { rawtext:CommandRawText });

Hook direct

import { events } from "bdsx/event";
events.command.on((cmd, origin, ctx)=>{
    switch (cmd) {
    case 'whoami':
        if (ctx.origin.isServerCommandOrigin()) {
            console.log('You are the server console');
        } else {
            console.log('You are '+origin);
        }
        break;
    default: return; // process the default command
	}
    return 0; // suppress the command, It will mute 'Unknown command' message.
});