extern crate serenity; use std::env; use serenity::{ model::{channel::Message, gateway::Ready}, prelude::*, }; struct Handler; impl EventHandler for Handler { fn message(&self, _: Context, msg: Message) { if msg.content == "!messageme" { // If the `methods` 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. if let Err(why) = msg.author.dm(|m| m.content("Hello!")) { 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); } }