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 macro to generate "named parameters". This is useful to avoid manually using the "arguments" parameter and manually parsing types.
This is meant for use with the command Framework
.
Examples
Create a regular ping
command which takes no arguments:
ⓘThis example is not tested
command!(ping(_context, message, _args) { 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); } });