Skip to content

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.

The interaction id.

The bot’s id in this community.

The channel it happened in.

Who triggered it.

The bot’s effective permissions in the channel.

The invoker’s locale (BCP 47), if their client sent one.

For component interactions: the message holding the component.

When the host received it (ms).

pub fn split(i: Interaction) -> (Self, InteractionData)

Splits an interaction into its context and data.

pub fn respond(&self, response: Response) -> Result<Option<Id>, HostError>

Sends any initial Response. Returns the created message id, if any.

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.

See respond.

pub fn reply_ephemeral<impl Into<Reply>>(&self, reply: impl Into<Reply>) -> Result<Option<Id>, HostError>

Answers with a message only the invoker sees.

See respond.

pub fn defer(&self, ephemeral: bool) -> Result<Option<Id>, HostError>

Shows “thinking…” and buys 15 minutes; finish with edit_original.

See respond.

pub fn defer_update(&self) -> Result<Option<Id>, HostError>

Acknowledges a component click without changing anything yet.

See respond.

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

See respond.

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.

See respond.

pub fn followup<impl Into<Reply>>(&self, reply: impl Into<Reply>) -> Result<Option<Id>, HostError>

Sends a follow-up message (at most 10).

The host’s refusal.

pub fn edit_original<impl Into<Reply>>(&self, reply: impl Into<Reply>) -> Result<(), HostError>

Replaces the original response.

The host’s refusal.

pub fn delete_original(&self) -> Result<(), HostError>

Deletes the original response.

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.

The host’s refusal (FORBIDDEN with reason dms_closed when the member does not take DMs from bots).

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

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

The host’s refusal.

Clone, Debug

Full rustdoc page