Skip to main content

Command

Trait Command 

Source
pub trait Command: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn execute(&self, args: &CommandArgs, ctx: &dyn Context);
}
Expand description

A server command that can be executed by players or the console.

§Example

use basalt_api::command::Command;
use crate::context::Context;

pub struct PingCommand;

impl Command for PingCommand {
    fn name(&self) -> &str { "ping" }
    fn description(&self) -> &str { "Responds with pong" }
    fn execute(&self, _args: &CommandArgs, ctx: &dyn Context) {
        ctx.chat().send("Pong!");
    }
}

Required Methods§

Source

fn name(&self) -> &str

The command name without the leading /.

Source

fn description(&self) -> &str

A short description for the help listing.

Source

fn execute(&self, args: &CommandArgs, ctx: &dyn Context)

Executes the command with parsed arguments.

Implementors§