Skip to content

Intents

Intents is a 32-bit flag set that tells the QQ gateway which event categories your bot wants to receive. Subscribing only to what you need keeps gateway traffic small and avoids dispatcher work for events you'd discard.

rust
pub struct Intents { pub bits: u32 }

Intents is Copy, supports the bitwise operators (|, &, ^, !), and serializes to its raw u32 for the gateway Identify payload.

Constructors

  • Intents::new() — empty (bits == 0).
  • Intents::default() — the standard public preset: all() with GUILD_MESSAGES and FORUMS cleared. ENTER_AIO also remains opt-in.
  • Intents::all() — every standard flag represented by the framework except ENTER_AIO. It includes privileged flags, so use it only if those permissions are approved.
  • Intents::from_bits(bits) — wrap a raw integer received from configuration.

Flag catalogue

Each row lists the public Rust constant, the underlying bit, the with_* builder, and a short description.

ConstantBitBuilderWhat it covers
Intents::GUILDS1 << 0with_guildsGuild create / update / delete + channel CRUD.
Intents::GUILD_MEMBERS1 << 1with_guild_membersMember add / update / remove.
Intents::GUILD_MESSAGES (privileged)1 << 9with_guild_messagesAll guild messages — needs special approval.
Intents::GUILD_MESSAGE_REACTIONS1 << 10with_guild_message_reactionsReaction add / delete events in guild messages.
Intents::DIRECT_MESSAGE1 << 12with_direct_messageDirect-message create / delete events.
Intents::OPEN_FORUM_EVENT1 << 18with_open_forum_eventOpen-forum activity (public forums).
Intents::AUDIO_OR_LIVE_CHANNEL_MEMBER1 << 19with_audio_or_live_channel_memberVoice / live channel member changes.
Intents::ENTER_AIO1 << 23with_enter_aioUser entering AIO (chat panel).
Intents::PUBLIC_MESSAGES1 << 25with_public_messagesGroup @bot messages, C2C messages, friend events.
Intents::INTERACTION1 << 26with_interactionInteraction (button / app) callbacks.
Intents::MESSAGE_AUDIT1 << 27with_message_auditMessage audit pass / reject.
Intents::FORUMS (privileged)1 << 28with_forumsAll forum events — needs special approval.
Intents::AUDIO_ACTION1 << 29with_audio_actionAudio start / finish / on-mic / off-mic.
Intents::PUBLIC_GUILD_MESSAGES1 << 30with_public_guild_messages@bot mentions and public message-delete events.

Inspection

For each flag there's a matching predicate (no parameters): intents.guilds(), intents.public_guild_messages(), etc. Two helpers cover common groupings:

  • intents.contains(bits) — generic membership check against a raw bit.
  • intents.has_privileged()true when GUILD_MESSAGES or FORUMS are enabled.

Mutation

  • with_intent(bits) / without_intent(bits) — generic chainable setters.
  • bits() — return the raw u32.
  • Display impl prints Intents(GUILDS | DIRECT_MESSAGE | …) for logging.

Examples

rust
// 1. Public preset — no privileged events and no ENTER_AIO.
let default_intents = Intents::default();

// 2. Strict custom subscription via builder.
let custom = Intents::new()
    .with_guilds()
    .with_public_guild_messages()
    .with_direct_message();

// 3. Bitwise composition.
let public = Intents::from_bits(
    Intents::GUILDS | Intents::PUBLIC_GUILD_MESSAGES | Intents::DIRECT_MESSAGE,
);

// 4. Drop a flag at runtime.
let trimmed = Intents::all().without_intent(Intents::FORUMS);

Privileged intents

GUILD_MESSAGES and FORUMS require manual approval in the QQ Developer Portal. Bots without that approval will be disconnected by the gateway when they identify with these bits set. Intents::default() deliberately omits them so the same code path works for all bots. ENTER_AIO is separate from the public preset and is enabled only by with_enter_aio().

rust
if intents.has_privileged() && !your_bot_is_approved {
    return Err("privileged intents requested without approval".into());
}

See also

  • Bot API — every endpoint that produces events you might subscribe to.
  • Event handler — receives the events selected by these intents.
  • Gateway guide — how the framework opens a session with the chosen intents.

Released under the MIT License.