diff options
| author | acdenisSK <[email protected]> | 2017-07-02 14:33:23 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-07-02 18:29:29 +0200 |
| commit | 511ec87280e8ddec6589f48fec8260bf2e598bdb (patch) | |
| tree | 008846c1531ecd47887abb9623b98a960b1fa808 /src/model/channel/attachment.rs | |
| parent | Add a `quit` function` (diff) | |
| download | serenity-511ec87280e8ddec6589f48fec8260bf2e598bdb.tar.xz serenity-511ec87280e8ddec6589f48fec8260bf2e598bdb.zip | |
Fix doc tests
Diffstat (limited to 'src/model/channel/attachment.rs')
| -rw-r--r-- | src/model/channel/attachment.rs | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/src/model/channel/attachment.rs b/src/model/channel/attachment.rs index 015c18e..2238174 100644 --- a/src/model/channel/attachment.rs +++ b/src/model/channel/attachment.rs @@ -46,52 +46,55 @@ impl Attachment { /// Download all of the attachments associated with a [`Message`]: /// /// ```rust,no_run - /// use serenity::Client; + /// use serenity::prelude::*; + /// use serenity::model::*; /// use std::env; /// use std::fs::File; /// use std::io::Write; /// use std::path::Path; /// - /// let token = env::var("DISCORD_TOKEN").expect("token in environment"); - /// let mut client = Client::new(&token); + /// struct Handler; /// - /// client.on_message(|_, message| { - /// for attachment in message.attachments { - /// let content = match attachment.download() { - /// Ok(content) => content, - /// Err(why) => { - /// println!("Error downloading attachment: {:?}", why); - /// let _ = message.channel_id.say("Error downloading attachment"); /// - /// return; - /// }, - /// }; + /// impl EventHandler for Handler { + /// fn on_message(&self, _: Context, message: Message) { + /// for attachment in message.attachments { + /// let content = match attachment.download() { + /// Ok(content) => content, + /// Err(why) => { + /// println!("Error downloading attachment: {:?}", why); + /// let _ = message.channel_id.say("Error downloading attachment"); /// - /// let mut file = match File::create(&attachment.filename) { - /// Ok(file) => file, - /// Err(why) => { - /// println!("Error creating file: {:?}", why); - /// let _ = message.channel_id.say("Error creating file"); + /// return; + /// }, + /// }; /// - /// return; - /// }, - /// }; + /// let mut file = match File::create(&attachment.filename) { + /// Ok(file) => file, + /// Err(why) => { + /// println!("Error creating file: {:?}", why); + /// let _ = message.channel_id.say("Error creating file"); /// - /// if let Err(why) = file.write(&content) { - /// println!("Error writing to file: {:?}", why); + /// return; + /// }, + /// }; /// - /// return; - /// } + /// if let Err(why) = file.write(&content) { + /// println!("Error writing to file: {:?}", why); /// - /// let _ = message.channel_id.say(&format!("Saved {:?}", attachment.filename)); - /// } - /// }); + /// return; + /// } /// - /// client.on_ready(|_context, ready| { - /// println!("{} is connected!", ready.user.name); - /// }); + /// let _ = message.channel_id.say(&format!("Saved {:?}", attachment.filename)); + /// } + /// } /// - /// let _ = client.start(); + /// fn on_ready(&self, _: Context, ready: Ready) { + /// println!("{} is connected!", ready.user.name); + /// } + /// } + /// let token = env::var("DISCORD_TOKEN").expect("token in environment"); + /// let mut client = Client::new(&token, Handler); client.start().unwrap(); /// ``` /// /// # Errors |