| Crates.io | discord_client_gateway |
| lib.rs | discord_client_gateway |
| version | 0.2.0 |
| created_at | 2025-03-24 14:23:29.087389+00 |
| updated_at | 2025-05-28 21:02:12.320455+00 |
| description | Undetected discord client gateway reimplementation |
| homepage | |
| repository | https://github.com/UwUDev/discord-client-rs |
| max_upload_size | |
| id | 1603830 |
| size | 169,657 |
A high-level Rust implementation of the Discord gateway, designed to provide a robust and efficient client-side connection to Discord's real-time WebSocket API.
This crate offers a seamless integration for Discord bot developers, featuring:
Whether you're building a simple bot or a complete Discord client reimplementation, this crate provides the tools you need to establish and maintain a reliable connection to Discord's gateway.
Add this crate to your Cargo.toml:
[dependencies]
discord_client_gateway = "0.1.0"
let token = "CLIENT_TOKEN".to_string();
let capabilities = 53607934; // Best if you want to receive all events
let client_build_nubmer = 402402; // You should always use the latest build number
// you can also fetch the build number from the crate `discord_client_rest`
let mut client = GatewayClient::connect(token, capabilities, client_build_nubmer)
.await
.unwrap();
loop {
let event = client.next_event().await.unwrap();
println!("{}", event);
// Print the new messages content
if let Event::MessageCreate(message_create) = event {
let centent = message_create.message.content.unwrap_or("No content".to_string());
println!("Message: {}", content);
}
}
This example shows how to subscribe to all guilds after receiving the Ready event.
You can just subscribe to the guilds you want to receive events from by giving the guild ids to the bulk_guild_subscribe method.
let event = client.next_event().await.unwrap();
println!("{}", event);
if let Event::Ready(ready) = event {
let mut ids: Vec<u64> = Vec::new();
let guilds = ready.guilds;
for guild in guilds {
let guild_id = guild.id;
ids.push(guild_id);
}
client.bulk_guild_subscribe(ids).await.unwrap();
}