Struct Context
zaun_bot::Context · Struct
pub struct Context { … }The interaction being handled, without its data (handlers get the data separately).
The first answer must be one of reply,
reply_ephemeral, respond,
defer, defer_update,
update_message or show_modal, within 3 s.
After it, use followup and edit_original for
15 minutes.
Fields
Section titled “Fields”id: Id
Section titled “id: Id”The interaction id.
bot_id: Id
Section titled “bot_id: Id”The bot’s id in this community.
channel_id: Id
Section titled “channel_id: Id”The channel it happened in.
member: Member
Section titled “member: Member”Who triggered it.
app_permissions: u64
Section titled “app_permissions: u64”The bot’s effective permissions in the channel.
locale: Option<String>
Section titled “locale: Option<String>”The invoker’s locale (BCP 47), if their client sent one.
message: Option<Message>
Section titled “message: Option<Message>”For component interactions: the message holding the component.
created_at: u64
Section titled “created_at: u64”When the host received it (ms).
Methods
Section titled “Methods”pub fn split(i: Interaction) -> (Self, InteractionData)Splits an interaction into its context and data.
respond
Section titled “respond”pub fn respond(&self, response: Response) -> Result<Option<Id>, HostError>Sends any initial Response. Returns the created message id, if any.
Errors
Section titled “Errors”The host’s refusal (already answered, too late, a message the bot may not send).
pub fn reply<impl Into<Reply>>(&self, reply: impl Into<Reply>) -> Result<Option<Id>, HostError>Answers with a message in the channel.
Errors
Section titled “Errors”See respond.
reply_ephemeral
Section titled “reply_ephemeral”pub fn reply_ephemeral<impl Into<Reply>>(&self, reply: impl Into<Reply>) -> Result<Option<Id>, HostError>Answers with a message only the invoker sees.
Errors
Section titled “Errors”See respond.
pub fn defer(&self, ephemeral: bool) -> Result<Option<Id>, HostError>Shows “thinking…” and buys 15 minutes; finish with edit_original.
Errors
Section titled “Errors”See respond.
defer_update
Section titled “defer_update”pub fn defer_update(&self) -> Result<Option<Id>, HostError>Acknowledges a component click without changing anything yet.
Errors
Section titled “Errors”See respond.
update_message
Section titled “update_message”pub fn update_message<impl Into<Reply>>(&self, reply: impl Into<Reply>) -> Result<Option<Id>, HostError>Replaces the message holding the clicked component (it must be the bot’s).
Errors
Section titled “Errors”See respond.
show_modal
Section titled “show_modal”pub fn show_modal<impl Into<Modal>>(&self, modal: impl Into<Modal>) -> Result<Option<Id>, HostError>Opens a modal for the invoker. Not allowed in answer to a modal submit.
Errors
Section titled “Errors”See respond.
followup
Section titled “followup”pub fn followup<impl Into<Reply>>(&self, reply: impl Into<Reply>) -> Result<Option<Id>, HostError>Sends a follow-up message (at most 10).
Errors
Section titled “Errors”The host’s refusal.
edit_original
Section titled “edit_original”pub fn edit_original<impl Into<Reply>>(&self, reply: impl Into<Reply>) -> Result<(), HostError>Replaces the original response.
Errors
Section titled “Errors”The host’s refusal.
delete_original
Section titled “delete_original”pub fn delete_original(&self) -> Result<(), HostError>Deletes the original response.
Errors
Section titled “Errors”The host’s refusal.
pub fn dm<impl Into<Reply>>(&self, member_id: &str, reply: impl Into<Reply>) -> Result<(Id, Id), HostError>Sends a direct message to a member (capability dms), for example the invoker:
ctx.dm(&ctx.member.member_id, "details"). Returns the DM’s channel id and the
message id.
Errors
Section titled “Errors”The host’s refusal (FORBIDDEN with reason dms_closed when the member does not take
DMs from bots).
set_presence
Section titled “set_presence”pub fn set_presence<impl Into<Option<crate::presence::Activity>>>(&self, status: Status, activity: impl Into<Option<Activity>>)Sets the bot’s status and activity (crate::presence::set).
set_status_text
Section titled “set_status_text”pub fn set_status_text<impl Into<String>>(&self, text: impl Into<String>) -> Result<(), HostError>Sets the bot’s custom status text (crate::presence::set_status_text).
Errors
Section titled “Errors”The host’s refusal.
Trait implementations
Section titled “Trait implementations”Clone, Debug