Skip to content

Events and the cache

For each community the client keeps a local copy of its profile, channels, roles and the members it has seen, kept current from the host’s events. Reading it needs no network round trip: community.channels(), community.roles(), community.members() in Rust; community.channels, .roles, .members (Collections, maps with find/filter/map) in JavaScript.

The client keeps no message history: fetch it from the host when you need it.

Rust delivers events from client.events() (blocking) or client.next_event(timeout); JavaScript from client.on(name, handler).

Rust Event:: JavaScript event When
Ready(community) ready a community is loaded and current
MessageCreate(message) messageCreate a message was posted
MessageUpdate { .. } messageUpdate a message was edited (partial message)
MessageDelete { .. } messageDelete a message was deleted (partial message)
MessageDeleteBulk { .. } messageDeleteBulk many messages were deleted (a ban’s cleanup)
ReactionAdd / ReactionRemove messageReactionAdd / messageReactionRemove reactions
ChannelCreate / ChannelUpdate / ChannelDelete channelCreate / channelUpdate / channelDelete channel changes, including access gained or lost
RoleCreate / RoleUpdate / RoleDelete roleCreate / roleUpdate / roleDelete role changes
MemberAdd / MemberUpdate / MemberRemove memberAdd / memberUpdate / memberRemove members joining, changing, leaving
PresencesReady(community) presencesReady who is online in a community loaded (just after ready)
PresenceUpdate { .. } presenceUpdate a member’s status or activity changed
VoiceStateUpdate voiceStateUpdate someone joined, left or (un)muted in voice
CommunityUpdate communityUpdate the community’s profile changed
CommunityDelete { .. } communityDelete you were kicked, banned or left
CommunityMoving / CommunityMoved / CommunityMoveRefused same names the owner moved the community to a new host; the client follows
Disconnect disconnect the connection to one host dropped
Offline / Online offline / online the network went away or came back
Warning warning something odd but recoverable happened
— change the store changed: save it (client.save())
— raw every event as the host sent it

Objects wrap the common commands. For anything else, client.command(community, channel, body) (Rust) sends any protocol command with a typed body from zaun_client::protocol::command and decodes the answer. JavaScript has client.raw for the low-level client.