Crates.io | descord |
lib.rs | descord |
version | 0.1.10 |
source | src |
created_at | 2024-03-16 06:40:50.787228 |
updated_at | 2024-03-25 06:36:25.553482 |
description | A minimal discord api wrapper. |
homepage | |
repository | https://github.com/thatmagicalcat/descord |
max_upload_size | |
id | 1175446 |
size | 171,719 |
Descord is a discord api wrapper.
use descord::prelude::*;
#[tokio::main]
async fn main() {
let mut client = Client::new(
"TOKEN",
GatewayIntent::MessageContent | GatewayIntent::GuildMessages,
"!" // default prefix
)
.await;
client.register_commands(vec![ping()]);
client.register_events(vec![ready()]);
client.login().await;
}
#[descord::command("ping")]
async fn ping(data: MessageData) {
let clock = std::time::Instant::now();
let msg = data.reply("Pong!").await;
let latency = clock.elapsed().as_millis();
msg.edit(format!("Pong! `{}ms`", latency)).await;
}
// Event type will be inferred from function name
#[descord::event_handler]
async fn ready(data: ReadyData) {
println!(
"Logged in as: {}#{}",
data.user.username, data.user.discriminator
);
}