Trait Bot
zaun_bot::Bot · Trait
pub trait Bot { … }A Zaun bot. Every handler has a no-op default; implement the ones you need.
The host calls one handler at a time, so &mut self state is safe. State lives only as
long as the instance; use crate::storage for anything that must survive a restart.
Event handlers run only for events the manifest’s events asks for (wire types such as
message.created, groups such as messages, members, dms, or *); see
docs/events.md. on_ready always runs first.
Methods
Section titled “Methods”on_start
Section titled “on_start”fn on_start(&mut self, config: &Config);The bot started (each instance start, before Bot::commands): a good place to set
its presence (crate::presence).
on_config
Section titled “on_config”fn on_config(&mut self, config: &Config);The owner changed the bot’s configuration while it runs: every value again, as at start. The bot is not restarted; refresh whatever it derived from the old values.
commands
Section titled “commands”fn commands(&mut self, config: &Config) -> Vec<ApplicationCommand>;The application commands to register when the bot starts.
on_command
Section titled “on_command”fn on_command(&mut self, ctx: Context, command: CommandData);A slash, user or message command was used. Answer within 3 s (or call
Context::defer); the runtime defers automatically at 2.5 s.
on_component
Section titled “on_component”fn on_component(&mut self, ctx: Context, component: ComponentData);A button was clicked or a select changed on one of the bot’s messages.
on_modal
Section titled “on_modal”fn on_modal(&mut self, ctx: Context, modal: ModalData);A modal the bot opened was submitted.
on_autocomplete
Section titled “on_autocomplete”fn on_autocomplete(&mut self, ctx: Context, command: CommandData) -> Vec<Choice>;The invoker is typing in an option with autocomplete. Return up to 25 choices.
on_timer
Section titled “on_timer”fn on_timer(&mut self, id: u64, tag: String);A timer from crate::timers fired.
on_event
Section titled “on_event”fn on_event(&mut self, ctx: EventContext, event: Event);Every event; the default calls the typed handlers below. Override it to see events raw, before (or instead of) them.
on_ready
Section titled “on_ready”fn on_ready(&mut self, ctx: EventContext, me: Ready);The bot’s connection is up: its ids and community. Always the first event.
on_message_create
Section titled “on_message_create”fn on_message_create(&mut self, ctx: EventContext, message: Message, is_dm: bool);A message was posted (messages). is_dm: in a direct message with the bot.
on_message_update
Section titled “on_message_update”fn on_message_update(&mut self, ctx: EventContext, message: Message, is_dm: bool);A message was edited (messages).
on_message_delete
Section titled “on_message_delete”fn on_message_delete(&mut self, ctx: EventContext, channel_id: Id, message_id: Id);A message was deleted (messages).
on_message_delete_bulk
Section titled “on_message_delete_bulk”fn on_message_delete_bulk(&mut self, ctx: EventContext, channel_id: Id, ids: Vec<Id>);Messages were deleted together, by a ban (messages).
on_reaction_add
Section titled “on_reaction_add”fn on_reaction_add(&mut self, ctx: EventContext, reaction: Reaction);A reaction was added (reactions).
on_reaction_remove
Section titled “on_reaction_remove”fn on_reaction_remove(&mut self, ctx: EventContext, reaction: Reaction);A reaction was removed (reactions).
on_member_join
Section titled “on_member_join”fn on_member_join(&mut self, ctx: EventContext, member: Member);A member joined (members, capability members).
on_member_update
Section titled “on_member_update”fn on_member_update(&mut self, ctx: EventContext, member: Member);A member changed their name (members).
on_member_leave
Section titled “on_member_leave”fn on_member_leave(&mut self, ctx: EventContext, member_id: Id);A member left, was kicked or banned (members).
on_removed
Section titled “on_removed”fn on_removed(&mut self, ctx: EventContext, reason: String);The bot itself was removed (kicked, banned); it stops right after.
on_member_roles_update
Section titled “on_member_roles_update”fn on_member_roles_update(&mut self, ctx: EventContext, roles: MemberRoles);A member’s roles changed (members).
on_member_timeout
Section titled “on_member_timeout”fn on_member_timeout(&mut self, ctx: EventContext, timeout: MemberTimeout);A member was timed out, or their timeout cleared (members).
on_channel_create
Section titled “on_channel_create”fn on_channel_create(&mut self, ctx: EventContext, channel: Channel);A channel the bot can see was created (channels).
on_channel_update
Section titled “on_channel_update”fn on_channel_update(&mut self, ctx: EventContext, channel: Channel);A channel changed (channels).
on_channel_delete
Section titled “on_channel_delete”fn on_channel_delete(&mut self, ctx: EventContext, channel_id: Id);A channel was deleted, or the bot lost access (channels).
on_role_create
Section titled “on_role_create”fn on_role_create(&mut self, ctx: EventContext, role: Role);A role was created (roles).
on_role_update
Section titled “on_role_update”fn on_role_update(&mut self, ctx: EventContext, role: Role);A role changed (roles).
on_role_delete
Section titled “on_role_delete”fn on_role_delete(&mut self, ctx: EventContext, role_id: Id);A role was deleted (roles).
on_typing_start
Section titled “on_typing_start”fn on_typing_start(&mut self, ctx: EventContext, typing: Typing);Members are typing in a channel the bot can see (typing).
on_presence_update
Section titled “on_presence_update”fn on_presence_update(&mut self, ctx: EventContext, presence: Presence);A member’s presence changed (presence, capability presence).
on_community_update
Section titled “on_community_update”fn on_community_update(&mut self, ctx: EventContext, profile: CommunityProfile);The community’s settings changed (community).
on_commands_update
Section titled “on_commands_update”fn on_commands_update(&mut self, ctx: EventContext, bot_id: Id);A bot’s command list changed (commands); its bot id.
on_dm_open
Section titled “on_dm_open”fn on_dm_open(&mut self, ctx: EventContext, channel: Channel);A DM with the bot was opened, by the bot or a member (dms, capability dms).
on_dm_close
Section titled “on_dm_close”fn on_dm_close(&mut self, ctx: EventContext, channel_id: Id);The bot closed a DM (dms).
on_raw
Section titled “on_raw”fn on_raw(&mut self, ctx: EventContext, event: RawEvent);An event without a typed handler: its wire type and JSON body.
on_voice_event
Section titled “on_voice_event”fn on_voice_event(&mut self, event: VoiceEvent);Something happened in the bot’s voice stay or player (crate::Voice): a track
started, ended or failed, someone joined or left, or the stay ended.