Event Handling
Each gateway event is one method on EventHandler. You implement only the ones you care about; everything else has an empty default. Examples covering the non-message event surface:
- Guild member join/update/leave:
examples/events/guild_member.rs(guild_member_add,guild_member_update,guild_member_remove) - Open forum threads/posts/replies:
examples/events/open_forum.rs(open_forum_thread_create,open_forum_post_create,open_forum_reply_create, ...) - Voice / live channel enter/exit:
examples/events/audio_or_live_channel_member.rs(audio_or_live_channel_member_enter/_exit) - C2C friend add/remove + active-message toggle:
examples/c2c/manage_event.rs(friend_add,friend_del,c2c_msg_reject,c2c_msg_receive) - Group robot add/remove + active-message toggle:
examples/group/manage_event.rs(group_add_robot,group_del_robot,group_msg_reject,group_msg_receive)
Wiring
Each event family has its own intent flag. Forgetting the flag means the handler is silent, not an error. Mix the flags you need:
rust
let intents = Intents::new()
.with_guild_members() // examples/events/guild_member.rs
.with_open_forum_event() // examples/events/open_forum.rs
.with_audio_or_live_channel_member() // examples/events/audio_or_live_channel_member.rs
.with_public_messages(); // c2c/group manage eventsInside the handler, the session dereferences to BotApi, so you can react by calling APIs directly on session (for example, session.create_direct_message + session.send_direct_message to greet a new member). Group/C2C manage sessions also provide session.send_message(...) and fill event_id / msg_seq automatically when possible.
See also
- Guide:
docs/guide/intents.md,docs/guide/client-handler.md - Full list of
EventHandlermethods:src/client/handler.rs - Examples listed above under
examples/