basic pingpong bot

This commit is contained in:
Ash Vollmer 2026-08-02 17:38:14 +02:00
parent ce3b7222e1
commit 35c7c6a02c
3 changed files with 2315 additions and 2 deletions

View file

@ -1,3 +1,40 @@
fn main() {
println!("Hello, world!");
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:?}");
}
}