Macro serenity::command[][src]

macro_rules! command {
    ($fname:ident($c:ident) $b:block) => { ... };
    ($fname:ident($c:ident, $m:ident) $b:block) => { ... };
    ($fname:ident($c:ident, $m:ident, $a:ident) $b:block) => { ... };
}

A convenience macro for generating a struct fulfilling the Command trait.

This is meant for use with the Framework, specifically Framework::{cmd/command}.

If you're just looking for a simple "register this function as a command", use Framework::on.

Examples

Create a regular ping command which takes no arguments:

This example is not tested
command!(ping(_context, message) {
    if let Err(why) = message.reply("Pong!") {
        println!("Error sending pong: {:?}", why);
    }
});

Create a command named multiply which accepts 2 floats and multiplies them, sending the product as a reply:

This example is not tested
command!(multiply(_context, message, args) {
    let first = args.single::<f64>().unwrap();
    let second = args.single::<f64>().unwrap();
    let product = first * second;

    if let Err(why) = message.reply(&product.to_string()) {
        println!("Error sending product: {:?}", why);
    }
});