Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Client
✓ use serenity::Client;
Create a Discord bot that responds to !ping with Pong!.
use serenity::Client;
use serenity::prelude::*;
struct Handler;
#[serenity::async_trait]
impl EventHandler for Handler {
async fn message(&self, ctx: Context, msg: Message) {
if msg.content == "!ping" {
let _ = msg.channel_id.say(&ctx.http, "Pong!").await;
}
}
}
#[tokio::main]
async fn main() {
let token = std::env::var("DISCORD_TOKEN").unwrap();
let mut client = Client::builder(&token, GatewayIntents::all())
.event_handler(Handler)
.await
.expect("Error creating client");
client.start().await.unwrap();
}
Upgrade
Version history
0.12.5latest on crates.io
Audit
Dependencies
No dependency data recorded yet.