Skip to content

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.

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).

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.

fn commands(&mut self, config: &Config) -> Vec<ApplicationCommand>;

The application commands to register when the bot starts.

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.

fn on_component(&mut self, ctx: Context, component: ComponentData);

A button was clicked or a select changed on one of the bot’s messages.

fn on_modal(&mut self, ctx: Context, modal: ModalData);

A modal the bot opened was submitted.

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.

fn on_timer(&mut self, id: u64, tag: String);

A timer from crate::timers fired.

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.

fn on_ready(&mut self, ctx: EventContext, me: Ready);

The bot’s connection is up: its ids and community. Always the first event.

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.

fn on_message_update(&mut self, ctx: EventContext, message: Message, is_dm: bool);

A message was edited (messages).

fn on_message_delete(&mut self, ctx: EventContext, channel_id: Id, message_id: Id);

A message was deleted (messages).

fn on_message_delete_bulk(&mut self, ctx: EventContext, channel_id: Id, ids: Vec<Id>);

Messages were deleted together, by a ban (messages).

fn on_reaction_add(&mut self, ctx: EventContext, reaction: Reaction);

A reaction was added (reactions).

fn on_reaction_remove(&mut self, ctx: EventContext, reaction: Reaction);

A reaction was removed (reactions).

fn on_member_join(&mut self, ctx: EventContext, member: Member);

A member joined (members, capability members).

fn on_member_update(&mut self, ctx: EventContext, member: Member);

A member changed their name (members).

fn on_member_leave(&mut self, ctx: EventContext, member_id: Id);

A member left, was kicked or banned (members).

fn on_removed(&mut self, ctx: EventContext, reason: String);

The bot itself was removed (kicked, banned); it stops right after.

fn on_member_roles_update(&mut self, ctx: EventContext, roles: MemberRoles);

A member’s roles changed (members).

fn on_member_timeout(&mut self, ctx: EventContext, timeout: MemberTimeout);

A member was timed out, or their timeout cleared (members).

fn on_channel_create(&mut self, ctx: EventContext, channel: Channel);

A channel the bot can see was created (channels).

fn on_channel_update(&mut self, ctx: EventContext, channel: Channel);

A channel changed (channels).

fn on_channel_delete(&mut self, ctx: EventContext, channel_id: Id);

A channel was deleted, or the bot lost access (channels).

fn on_role_create(&mut self, ctx: EventContext, role: Role);

A role was created (roles).

fn on_role_update(&mut self, ctx: EventContext, role: Role);

A role changed (roles).

fn on_role_delete(&mut self, ctx: EventContext, role_id: Id);

A role was deleted (roles).

fn on_typing_start(&mut self, ctx: EventContext, typing: Typing);

Members are typing in a channel the bot can see (typing).

fn on_presence_update(&mut self, ctx: EventContext, presence: Presence);

A member’s presence changed (presence, capability presence).

fn on_community_update(&mut self, ctx: EventContext, profile: CommunityProfile);

The community’s settings changed (community).

fn on_commands_update(&mut self, ctx: EventContext, bot_id: Id);

A bot’s command list changed (commands); its bot id.

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).

fn on_dm_close(&mut self, ctx: EventContext, channel_id: Id);

The bot closed a DM (dms).

fn on_raw(&mut self, ctx: EventContext, event: RawEvent);

An event without a typed handler: its wire type and JSON body.

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.

Full rustdoc page