aboutsummaryrefslogtreecommitdiff
path: root/examples/03_struct_utilities/src
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-06-29 12:31:05 +0200
committeracdenisSK <[email protected]>2017-06-29 12:31:05 +0200
commit35826915a174c7f3e5d82bbc320d3238ae308d8c (patch)
tree7f59e067e778aa2eb6228eb0034bdcae46f7c1b1 /examples/03_struct_utilities/src
parentWhoops, and add a fail-safe to an upcomming pr to the compiler (diff)
downloadserenity-35826915a174c7f3e5d82bbc320d3238ae308d8c.tar.xz
serenity-35826915a174c7f3e5d82bbc320d3238ae308d8c.zip
Also update examples
Diffstat (limited to 'examples/03_struct_utilities/src')
-rw-r--r--examples/03_struct_utilities/src/main.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/examples/03_struct_utilities/src/main.rs b/examples/03_struct_utilities/src/main.rs
index 8802fba..5f777bd 100644
--- a/examples/03_struct_utilities/src/main.rs
+++ b/examples/03_struct_utilities/src/main.rs
@@ -1,15 +1,13 @@
extern crate serenity;
-use serenity::Client;
+use serenity::prelude::*;
+use serenity::model::*;
use std::env;
-fn main() {
- // Configure the client with your Discord bot token in the environment.
- let token = env::var("DISCORD_TOKEN")
- .expect("Expected a token in the environment");
- let mut client = Client::new(&token);
+struct Handler;
- client.on_message(|_ctx, msg| {
+impl EventHandler for Handler {
+ fn on_message(&self, _: Context, msg: Message) {
if msg.content == "!messageme" {
// If the `methods` feature is enabled, then model structs will
// have a lot of useful methods implemented, to avoid using an
@@ -23,11 +21,18 @@ fn main() {
println!("Error when direct messaging user: {:?}", why);
}
}
- });
+ }
- client.on_ready(|_ctx, ready| {
+ fn on_ready(&self, _: Context, ready: Ready) {
println!("{} is connected!", ready.user.name);
- });
+ }
+}
+
+fn main() {
+ // Configure the client with your Discord bot token in the environment.
+ let token = env::var("DISCORD_TOKEN")
+ .expect("Expected a token in the environment");
+ let mut client = Client::new(&token, Handler);
if let Err(why) = client.start() {
println!("Client error: {:?}", why);