Feat. Bot initialisation code along with message handling code
This commit is contained in:
parent
7375fac2f9
commit
1da36628bc
1 changed files with 25 additions and 1 deletions
26
src/main.rs
26
src/main.rs
|
@ -1,5 +1,29 @@
|
||||||
use dotenv::dotenv;
|
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();
|
dotenv().ok();
|
||||||
let token = std::env::var("TOKEN").expect("TOKEN must be set");
|
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:?}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue