Skip to main content

Bot

Trait Bot 

Source
pub trait Bot: Default + 'static {
Show 36 methods // Provided methods fn on_start(&mut self, config: &Config) { ... } fn on_config(&mut self, config: &Config) { ... } fn commands(&mut self, config: &Config) -> Vec<ApplicationCommand> { ... } fn on_command(&mut self, ctx: Context, command: CommandData) { ... } fn on_component(&mut self, ctx: Context, component: ComponentData) { ... } fn on_modal(&mut self, ctx: Context, modal: ModalData) { ... } fn on_autocomplete( &mut self, ctx: Context, command: CommandData, ) -> Vec<Choice> { ... } fn on_timer(&mut self, id: u64, tag: String) { ... } fn on_event(&mut self, ctx: EventContext, event: Event) { ... } fn on_ready(&mut self, ctx: EventContext, me: Ready) { ... } fn on_message_create( &mut self, ctx: EventContext, message: Message, is_dm: bool, ) { ... } fn on_message_update( &mut self, ctx: EventContext, message: Message, is_dm: bool, ) { ... } fn on_message_delete( &mut self, ctx: EventContext, channel_id: Id, message_id: Id, ) { ... } fn on_message_delete_bulk( &mut self, ctx: EventContext, channel_id: Id, ids: Vec<Id>, ) { ... } fn on_reaction_add(&mut self, ctx: EventContext, reaction: Reaction) { ... } fn on_reaction_remove(&mut self, ctx: EventContext, reaction: Reaction) { ... } fn on_member_join(&mut self, ctx: EventContext, member: Member) { ... } fn on_member_update(&mut self, ctx: EventContext, member: Member) { ... } fn on_member_leave(&mut self, ctx: EventContext, member_id: Id) { ... } fn on_removed(&mut self, ctx: EventContext, reason: String) { ... } fn on_member_roles_update(&mut self, ctx: EventContext, roles: MemberRoles) { ... } fn on_member_timeout(&mut self, ctx: EventContext, timeout: MemberTimeout) { ... } fn on_channel_create(&mut self, ctx: EventContext, channel: Channel) { ... } fn on_channel_update(&mut self, ctx: EventContext, channel: Channel) { ... } fn on_channel_delete(&mut self, ctx: EventContext, channel_id: Id) { ... } fn on_role_create(&mut self, ctx: EventContext, role: Role) { ... } fn on_role_update(&mut self, ctx: EventContext, role: Role) { ... } fn on_role_delete(&mut self, ctx: EventContext, role_id: Id) { ... } fn on_typing_start(&mut self, ctx: EventContext, typing: Typing) { ... } fn on_presence_update(&mut self, ctx: EventContext, presence: Presence) { ... } fn on_community_update( &mut self, ctx: EventContext, profile: CommunityProfile, ) { ... } fn on_commands_update(&mut self, ctx: EventContext, bot_id: Id) { ... } fn on_dm_open(&mut self, ctx: EventContext, channel: Channel) { ... } fn on_dm_close(&mut self, ctx: EventContext, channel_id: Id) { ... } fn on_raw(&mut self, ctx: EventContext, event: RawEvent) { ... } fn on_voice_event(&mut self, event: VoiceEvent) { ... }
}
Expand description

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.

Provided Methods§

Source

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

Source

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.

Source

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

The application commands to register when the bot starts.

Source

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.

Source

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

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

Source

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

A modal the bot opened was submitted.

Source

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.

Source

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

A timer from crate::timers fired.

Source

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.

Source

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

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

Source

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.

Source

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

A message was edited (messages).

Source

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

A message was deleted (messages).

Source

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

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

Source

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

A reaction was added (reactions).

Source

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

A reaction was removed (reactions).

Source

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

A member joined (members, capability members).

Source

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

A member changed their name (members).

Source

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

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

Source

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

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

Source

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

A member’s roles changed (members).

Source

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

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

Source

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

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

Source

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

A channel changed (channels).

Source

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

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

Source

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

A role was created (roles).

Source

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

A role changed (roles).

Source

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

A role was deleted (roles).

Source

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

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

Source

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

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

Source

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

The community’s settings changed (community).

Source

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

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

Source

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

Source

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

The bot closed a DM (dms).

Source

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

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

Source

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§