aboutsummaryrefslogtreecommitdiff
path: root/examples/07_sample_bot_structure/src/main.rs
blob: 37227ccc39c9803ffb84ed7bee93854d93c81bb7 (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
24
25
26
27
28
29
30
31
32
33
34
35
//! Requires the 'framework' feature flag be enabled in your project's
//! `Cargo.toml`.
//!
//! This can be enabled by specifying the feature in the dependency section:
//!
//! ```toml
//! [dependencies.serenity]
//! git = "https://github.com/zeyla/serenity.git"
//! features = ["framework"]
//! ```

#[macro_use]
extern crate serenity;

mod commands;

use serenity::prelude::*;
use serenity::framework::BuiltinFramework;
use std::env;

struct Handler; impl EventHandler for Handler {}

fn main() {
    let mut client = Client::new(&env::var("DISCORD_TOKEN").unwrap(), Handler);

    client.with_framework(BuiltinFramework::new()
        .configure(|c| c.prefix("~"))
        .command("ping", |c| c.exec(commands::meta::ping))
        .command("latency", |c| c.exec(commands::meta::latency))
        .command("multiply", |c| c.exec(commands::math::multiply)));

    if let Err(why) = client.start() {
        println!("Client error: {:?}", why);
    }
}