diself
A modern async Rust library for building Discord selfbot workflows with a clean API, typed models, and a resilient gateway runtime.
Disclaimer
This project is intended for authorized and compliant use only.
- Make sure your usage complies with Discord's Terms of Service and platform policies.
- If you are using this for coursework, internal tooling, or controlled environments, ensure explicit authorization.
- Maintainers and contributors are not responsible for misuse.
Features
- Async-first -- built on
tokio, fully non-blocking - Event-driven -- implement
EventHandlerand react to 60+ gateway events - Resilient gateway -- automatic reconnect, resume, heartbeat ACK timeout, backoff with jitter, configurable max reconnect attempts
- Typed models -- channels, messages, guilds, roles, permissions, embeds, reactions, polls, ...
- Configurable cache -- users, channels, guilds, relationships (enable/disable per category)
- Builder ergonomics --
ClientBuilder,EmbedBuilder,CreateMessage - HTTP hardening -- automatic rate-limit retry, configurable request delay, typed
Error::Apivariant - Graceful shutdown --
Client::shutdown()for cooperative task cancellation
Installation
Add to your Cargo.toml:
[]
= "0.3.0"
= { = "1", = ["full"] }
Quick Start
use *;
;
async
Client Builder
ClientBuilder provides a clean, configurable entrypoint:
let client = builder?
.without_cache
.with_request_delay
.with_captcha_handler
.build;
Sending Messages
Simple text message:
ctx.send_message.await?;
Rich message with embeds:
use *;
let embed = new
.title
.description
.color
.field
.field
.footer
.build;
let msg = new
.content
.embed;
ctx.send_message_advanced.await?;
Reply to a message:
let reply = new
.content
.reply_to;
ctx.send_message_advanced.await?;
Message History & Search
// Fetch last 50 messages
let messages = ctx.get_messages.await?;
// Fetch with pagination
let older = ctx.channels.get_messages.await?;
// Search messages in a guild
let results = ctx.guilds.search_messages.await?;
// Pin / unpin
ctx.channels.pin_message.await?;
ctx.channels.unpin_message.await?;
let pinned = ctx.channels.get_pinned_messages.await?;
// Purge own messages (deletes one by one, rate-limit aware)
let deleted = ctx.purge_own_messages.await?;
Graceful Shutdown
Run the client in a task and stop it cooperatively:
use Arc;
let client = new;
let runner = clone;
let task = spawn;
ctrl_c.await?;
client.shutdown;
let _ = task.await;
Gateway Reliability
The gateway runtime handles:
- Automatic reconnect with configurable max attempts (default 10)
- Session resume (
RESUMEopcode) - Heartbeat with ACK timeout detection
RECONNECTandINVALID_SESSIONhandling- Exponential backoff with jitter
Managers API
Context exposes endpoint managers for ergonomic calls:
| Manager | Access | Coverage |
|---|---|---|
| Users | ctx.users |
Profile, avatar, settings |
| Guilds | ctx.guilds |
Members, roles, bans, search |
| Channels | ctx.channels |
Messages, threads, pins, permissions |
| Relationships | ctx.relationships |
Friends, blocks, requests |
let me = ctx.users.me.await?;
let guilds = ctx.guilds.list.await?;
let dms = ctx.channels.dm_channels.await?;
Examples
| Example | Description |
|---|---|
examples/bot.rs |
Command handler with !ping and !echo |
examples/cache_example.rs |
Cache configuration and inspection |
examples/hello_gateway.rs |
Raw gateway connection test |
DISCORD_TOKEN="..."
Development
Live endpoint smoke tests (requires a real token):
DISCORD_TOKEN="..."
Roadmap
Planned for upcoming releases:
- File upload / multipart in
CreateMessage(0.3.1) - Rate limit bucket tracking (pre/post request)
- Webhook management
- Voice gateway support
- Broader integration tests (gateway lifecycle, HTTP edge cases)
Contributing
Contributions are welcome! Please read CONTRIBUTING.md before getting started.
License
MIT. See LICENSE.