diff options
| author | Austin Hellyer <[email protected]> | 2016-11-21 11:15:03 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-21 11:15:03 -0800 |
| commit | d5a1985f8bd57b3fb487b979188a56dccababa2b (patch) | |
| tree | fb4513b69f2cf60eda2b6e22f9ab1efa225e9da8 /examples/06_command_framework.rs | |
| parent | No-run on context doc example (diff) | |
| download | serenity-d5a1985f8bd57b3fb487b979188a56dccababa2b.tar.xz serenity-d5a1985f8bd57b3fb487b979188a56dccababa2b.zip | |
Add framework command named arguments
Diffstat (limited to 'examples/06_command_framework.rs')
| -rw-r--r-- | examples/06_command_framework.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/examples/06_command_framework.rs b/examples/06_command_framework.rs index c7300aa..1324a2e 100644 --- a/examples/06_command_framework.rs +++ b/examples/06_command_framework.rs @@ -1,3 +1,4 @@ +#[macro_use] extern crate serenity; use serenity::client::Context; @@ -34,6 +35,7 @@ fn main() { .set_check("ping", owner_check) // Ensure only the owner can run this .on("emoji cat", cat_command) .on("emoji dog", dog_command) + .on("multiply", multiply) .on("some complex command", some_complex_command) // Commands can be in closure-form as well .on("about", |context, _message, _args| drop(context.say("A test bot")))); @@ -61,3 +63,11 @@ fn owner_check(_context: &Context, message: &Message) -> bool { fn some_complex_command(context: Context, _msg: Message, args: Vec<String>) { let _ = context.say(&format!("Arguments: {:?}", args)); } + +command!(multiply(context, _message, args, first: f64, second: f64) { + let res = first * second; + + let _ = context.say(&res.to_string()); + + println!("{:?}", args); +}); |