mirror of
https://forge.gzod01.fr/werobot/discoWeRo-Bot.git
synced 2024-11-17 10:28:03 +00:00
start making bot
This commit is contained in:
parent
beb953592c
commit
9622c3d0bc
2 changed files with 60 additions and 2 deletions
1
.env
Normal file
1
.env
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DISCORD_TOKEN=MTIzMDE2NjI2NTM3NzU5MTM5Ng.GVqsyl.ZvP2Kigd5VgP4eITdGqAGYfDw58YeXJYSJg4-A
|
61
src/main.rs
61
src/main.rs
|
@ -1,3 +1,60 @@
|
||||||
fn main() {
|
use std::env;
|
||||||
println!("Hello, world!");
|
|
||||||
|
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, msg: Message) {
|
||||||
|
if msg.content.starts_with("!") {
|
||||||
|
let command_with_exclam: &str = msg.content.strip_prefix("!").unwrap();
|
||||||
|
|
||||||
|
if command_with_exclam == "ping" {
|
||||||
|
if let Err(why) = msg.channel_id.say(&ctx.http, "Pong!").await {
|
||||||
|
println!("Error sending message: {why:?}");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("unknown command {command_with_exclam:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ["hello", "hi", "bonjour", "hola", "halo"]
|
||||||
|
.iter()
|
||||||
|
.any(|&s| msg.content.to_lowercase().contains(s))
|
||||||
|
{
|
||||||
|
if let Err(why) = msg.react(ctx, '👋').await {
|
||||||
|
println!("Error reacting message {why:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// async fn interaction_create(&self, ctx: Context, interaction: Interaction){
|
||||||
|
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
// Login with a bot token from the environment
|
||||||
|
let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
|
||||||
|
// Set gateway intents, which decides what events the bot will be notified about
|
||||||
|
let intents = GatewayIntents::GUILD_MESSAGES
|
||||||
|
| GatewayIntents::DIRECT_MESSAGES
|
||||||
|
| GatewayIntents::MESSAGE_CONTENT;
|
||||||
|
|
||||||
|
// Create a new instance of the Client, logging in as a bot.
|
||||||
|
let mut client = Client::builder(&token, intents)
|
||||||
|
.event_handler(Handler)
|
||||||
|
.await
|
||||||
|
.expect("Err creating client");
|
||||||
|
|
||||||
|
// Start listening for events by starting a single shard
|
||||||
|
if let Err(why) = client.start().await {
|
||||||
|
println!("Client error: {why:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fn main(){
|
||||||
|
// println!("helloworldf4a64fra984");
|
||||||
|
// }
|
||||||
|
|
Loading…
Reference in a new issue