Compare commits

..

2 commits

Author SHA1 Message Date
Ash Vollmer
35c7c6a02c basic pingpong bot 2026-08-02 17:38:14 +02:00
Ash Vollmer
ce3b7222e1 added .env to gitignore 2026-08-02 17:37:38 +02:00
4 changed files with 2316 additions and 2 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target
.env

2273
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -4,3 +4,6 @@ version = "0.1.0"
edition = "2024"
[dependencies]
serenity = "0.12.5"
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }
dotenv = "0.15.0"

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:?}");
}
}