-
Notifications
You must be signed in to change notification settings - Fork 559
/
main.rs
47 lines (39 loc) · 1.39 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::env;
use serenity::{
model::{channel::Message, gateway::Ready},
prelude::*,
};
struct Handler;
impl EventHandler for Handler {
fn message(&self, context: Context, msg: Message) {
if msg.content == "!messageme" {
// If the `utils`-feature is enabled, then model structs will
// have a lot of useful methods implemented, to avoid using an
// often otherwise bulky Context, or even much lower-level `rest`
// method.
//
// In this case, you can direct message a User directly by simply
// calling a method on its instance, with the content of the
// message.
let dm = msg.author.dm(&context, |m| {
m.content("Hello!");
m
});
if let Err(why) = dm {
println!("Error when direct messaging user: {:?}", why);
}
}
}
fn 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).expect("Err creating client");
if let Err(why) = client.start() {
println!("Client error: {:?}", why);
}
}