40 lines
1 KiB
Rust
40 lines
1 KiB
Rust
use std::env;
|
|
|
|
use dotenv::dotenv;
|
|
use serenity::{
|
|
all::{Context, EventHandler, GatewayIntents, Message, GATEWAY_VERSION},
|
|
async_trait, Client,
|
|
};
|
|
|
|
struct Handler;
|
|
|
|
#[async_trait]
|
|
impl EventHandler for Handler {
|
|
async fn message(&self, ctx: Context, msg: Message) {
|
|
if msg.content == "!ping" {
|
|
println!("found PING!");
|
|
if let Err(why) = msg.channel_id.say(&ctx.http, "Pong!").await {
|
|
println!("Error sending message: {why:?}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
println!("Hello, world!");
|
|
dotenv().ok();
|
|
let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
|
|
let intens = GatewayIntents::GUILD_MESSAGES
|
|
| GatewayIntents::DIRECT_MESSAGES
|
|
| GatewayIntents::MESSAGE_CONTENT;
|
|
|
|
let mut client = Client::builder(&token, intens)
|
|
.event_handler(Handler)
|
|
.await
|
|
.expect("Error creating client");
|
|
|
|
if let Err(why) = client.start().await {
|
|
println!("error: {why:?}");
|
|
}
|
|
}
|