diff options
| author | Zeyla Hellyer <[email protected]> | 2017-06-06 10:50:42 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-06-06 10:50:42 -0700 |
| commit | 630fc5e60d37ba328b7259184ad175aba9b943bd (patch) | |
| tree | 10233d7b2eed26b5628a5a031349af8769c22ccd | |
| parent | Clippy lints (diff) | |
| download | serenity-630fc5e60d37ba328b7259184ad175aba9b943bd.tar.xz serenity-630fc5e60d37ba328b7259184ad175aba9b943bd.zip | |
Add User::direct_message example
| -rw-r--r-- | src/model/user.rs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/model/user.rs b/src/model/user.rs index 53074e2..8f4d2d9 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -394,12 +394,34 @@ impl User { /// /// # Examples /// - /// Sending a message: + /// When a user sends a message with a content of `"~help"`, DM the author a + /// help message, and then react with `'👌'` to verify message sending: /// - /// ```rust,ignore - /// // assuming you are in a context + /// ```rust,no_run + /// # use serenity::Client; + /// # + /// # let mut client = Client::login(""); + /// # + /// use serenity::model::Permissions; + /// use serenity::CACHE; /// - /// let _ = message.author.direct_message(|m| m.content("Hello!")); + /// client.on_message(|_, msg| { + /// if msg.content == "~help" { + /// let url = CACHE.read().unwrap().user.invite_url(Permissions::empty()); + /// let help = format!("Helpful info here. Invite me with this link: <{}>", url); + /// + /// match msg.author.direct_message(|m| m.content(&help)) { + /// Ok(_) => { + /// let _ = msg.react('👌'); + /// }, + /// Err(why) => { + /// println!("Err sending help: {:?}", why); + /// + /// let _ = msg.reply("There was an error DMing you help."); + /// }, + /// }; + /// } + /// }); /// ``` /// /// [`PrivateChannel`]: struct.PrivateChannel.html |