[−][src]Macro serenity::command
A convenience macro for generating a struct fulfilling the Command
trait.
This is meant for use with the StandardFramework
, specifically Framework
::{cmd
/command
}.
If you're just looking for a simple "register this function as a command", use StandardFramework::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); } });