initial_bot #1

Open
eoghanconlon73 wants to merge 4 commits from initial_bot into main
Showing only changes of commit 1da36628bc - Show all commits

View file

@ -1,5 +1,29 @@
use dotenv::dotenv;
fn main() {
use serenity::async_trait;
use serenity::model::channel::Message;
use serenity::prelude::*;
struct Handler;
#[async_trait]
impl EventHandler for Handler {
async fn message(&self, ctx: Context, new_message: Message) {
if new_message.content == "!ping" {
if let Err(why) = new_message.channel_id.say(&ctx.http, "Pong!").await {
println!("Error sending message: {why:?}");
}
}
}
}
#[tokio::main]
async fn main() {
dotenv().ok();
let token = std::env::var("TOKEN").expect("TOKEN must be set");
let intents = GatewayIntents::GUILD_MESSAGES | GatewayIntents::DIRECT_MESSAGES | GatewayIntents::MESSAGE_CONTENT;
let mut client = Client::builder(&token, intents).event_handler(Handler).await.expect("Error creating bot.");
if let Err(why) = client.start().await {
println!("Client error: {why:?}");
}
}