basic pingpong bot
This commit is contained in:
parent
ce3b7222e1
commit
35c7c6a02c
3 changed files with 2315 additions and 2 deletions
2273
Cargo.lock
generated
Normal file
2273
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -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"
|
||||
|
|
|
|||
41
src/main.rs
41
src/main.rs
|
|
@ -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:?}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue