basic ping/pong bot
This commit is contained in:
parent
e57e23795a
commit
767d6a788f
31
src/main.rs
31
src/main.rs
|
@ -1,3 +1,30 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use serenity::model::channel::Message;
|
||||
use serenity::prelude::*;
|
||||
use std::fs::File;
|
||||
use std::io::{self, prelude::*, BufReader};
|
||||
|
||||
struct Handler;
|
||||
|
||||
impl EventHandler for Handler {
|
||||
fn message(&self, ctx: Context, msg: Message) {
|
||||
if msg.content == "!ping" {
|
||||
if let Err(cause) = msg.channel_id.say(&ctx.http, "pong") {
|
||||
println!("error sending message {:?}", cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let mut client = Client::new(
|
||||
read_token().expect("Could not read token from file `secret` in current directory"),
|
||||
Handler,
|
||||
)
|
||||
.expect("Error creating client");
|
||||
client.start().expect("Could not connect to discord");
|
||||
}
|
||||
|
||||
fn read_token() -> io::Result<String> {
|
||||
let reader = BufReader::new(File::open("secret")?);
|
||||
reader.lines().next().unwrap()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user