aboutsummaryrefslogtreecommitdiff
path: root/examples/01_basic_ping_bot/src/main.rs
blob: 8db4614cc3a7e1b32ee7fed650532d8ea65a0460 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
extern crate serenity;

use serenity::Client;
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::login_bot(&token);

    client.on_message(|context, message| {
        if message.content == "!ping" {
            let _ = context.say("Pong!");
        }
    });

    client.on_ready(|_context, ready| {
        println!("{} is connected!", ready.user.name);
    });

    let _ = client.start();
}