Expand description
§djs-model
Discord API v10 types — users, guilds, messages, gateway payloads and events — for djs-rs.
Status: alpha. Every documented Discord API v10 type: resources, gateway events and commands, interactions, REST bodies and responses, OAuth2 and webhook events. The API may still change between alpha releases; see the changelog.
discord.js counterpart: discord-api-types (v10)
This crate contains only data types and their (de)serialization. It has no networking and no async runtime, so it can be used by anything that speaks the Discord API: bots, dashboards, HTTP interaction servers, webhook receivers or tooling.
§Highlights
- Typed IDs.
Id<T>wraps aNonZeroU64with a zero-sized marker, so aUserIdcan never be passed where aChannelIdis expected.Id<T>andOption<Id<T>>are both 8 bytes. - Compact values. Strings are
CompactString(short strings stored inline, without allocation); image hashes are stored as 16 bytes instead of a 34-character string; timestamps are a singlei64. - Forward compatible. Unknown fields are ignored and unknown enum values are preserved
(
MessageType::Unknown(250)), so new Discord features never break deserialization. - Fast gateway decoding.
GatewayEventDeserializerdecodes each payload in a single pass straight into its concrete type, without an intermediate JSON value.
§Example
use djs_model::gateway::{DispatchEvent, GatewayEvent, GatewayEventDeserializer};
use serde::de::DeserializeSeed;
let json = r#"{"t":"MESSAGE_CREATE","s":7,"op":0,"d":{
"id":"1300000000000000000","channel_id":"1200000000000000000",
"author":{"id":"80351110224678912","username":"nelly","discriminator":"0",
"global_name":"Nelly","avatar":null},
"content":"!ping","timestamp":"2026-11-10T19:42:07.123000+00:00",
"edited_timestamp":null,"tts":false,"mention_everyone":false,"pinned":false,"type":0
}}"#;
let seed = GatewayEventDeserializer::from_json(json).unwrap();
let event = seed.deserialize(&mut serde_json::Deserializer::from_str(json)).unwrap();
if let GatewayEvent::Dispatch(_, DispatchEvent::MessageCreate(message)) = event {
assert_eq!(message.content, "!ping");
assert_eq!(message.author.display_name(), "Nelly");
}§Part of djs-rs
djs-model is one crate of djs-rs, a high-performance
Rust library for building Discord bots modelled on discord.js v14. It can be used on its own
or through the main djs-rs crate.
§License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Modules§
- application
- Applications: the apps (and their bot users) registered in the Developer Portal.
- application_
command - Application commands: slash commands, user and message context menu commands, and Activity entry points.
- application_
identity_ profile - Application identity profiles: game stats an app stores on a user’s identity in its game, shown in Game Stats Widgets on Discord profiles (D-072).
- application_
role_ connection_ metadata - Application role connection metadata: the fields an app defines for linked roles.
- audit_
log - Audit logs: the administrative actions taken in a guild, with what they changed.
- auto_
moderation - Auto Moderation: rules that block, flag or time out content automatically.
- channel
- Channels: guild text, voice, forum and media channels, threads and direct messages.
- component
- Components: interactive and layout elements of messages and modals (buttons, select menus, text inputs, and the Components V2 layout and content elements).
- emoji
- Emojis: custom guild and application emojis, and the partial emojis used in reactions, components and polls.
- entitlement
- Entitlements: a user’s or guild’s access to an app’s premium offering (an SKU).
- gateway
- The gateway: opcodes, intents, close codes, payloads and events.
- guild
- Guilds (servers).
- guild_
scheduled_ event - Guild scheduled events: events planned in a stage channel, a voice channel or somewhere else.
- guild_
template - Guild templates: codes that create a new guild from a snapshot of an existing one.
- id
- Typed Discord snowflake IDs.
- interaction
- Interactions: what a user does with an app (commands, components, modals), and the app’s responses.
- invite
- Invites to guilds, group DMs and voice channels.
- lobby
- Lobbies: groups of users of an app’s game (Discord Social SDK), managed by the app over HTTP, optionally linked to a guild channel.
- message
- Messages: their content, embeds, attachments, reactions, references and everything else attached to them.
- oauth2
- OAuth2: scopes an application can be authorized for, access tokens and the information of an authorization.
- permissions
- Permissions: what members and roles may do in a guild or channel.
- poll
- Polls attached to messages.
- rest
- Request bodies and response types of the REST API.
- sku
- SKUs: the premium offerings (one-time purchases and subscriptions) an app sells.
- soundboard
- Soundboard: short sounds users play in voice channels — Discord’s default sounds and each guild’s own.
- stage_
instance - Stage instances: live audio events in a stage channel.
- sticker
- Stickers: standard sticker packs and stickers uploaded to guilds.
- subscription
- Subscriptions: a user’s recurring payment for one of an app’s subscription SKUs.
- team
- Teams: groups of developers that own applications together.
- user
- Users.
- util
- General-purpose value types used throughout the Discord API.
- voice
- Voice: users’ voice connection states and the available voice regions.
- webhook
- Webhooks: post messages to a channel without a bot user.
- webhook_
event - Webhook events: events Discord sends over HTTP to an app’s webhook events URL (D-076).