Skip to main content

Context

Struct Context 

Source
pub struct Context {
    pub id: Id,
    pub bot_id: Id,
    pub channel_id: Id,
    pub member: Member,
    pub app_permissions: u64,
    pub locale: Option<String>,
    pub message: Option<Message>,
    pub created_at: u64,
}
Expand description

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§

§id: Id

The interaction id.

§bot_id: Id

The bot’s id in this community.

§channel_id: Id

The channel it happened in.

§member: Member

Who triggered it.

§app_permissions: u64

The bot’s effective permissions in the channel.

§locale: Option<String>

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

§message: Option<Message>

For component interactions: the message holding the component.

§created_at: u64

When the host received it (ms).

Implementations§

Source§

impl Context

Source

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

Splits an interaction into its context and data.

Source

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

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

§Errors

The host’s refusal (already answered, too late, a message the bot may not send).

Source

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

Answers with a message in the channel.

§Errors

See respond.

Source

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

Answers with a message only the invoker sees.

§Errors

See respond.

Source

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

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

§Errors

See respond.

Source

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

Acknowledges a component click without changing anything yet.

§Errors

See respond.

Source

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

Replaces the message holding the clicked component (it must be the bot’s).

§Errors

See respond.

Source

pub fn show_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

See respond.

Source

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

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

§Errors

The host’s refusal.

Source

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

Replaces the original response.

§Errors

The host’s refusal.

Source

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

Deletes the original response.

§Errors

The host’s refusal.

Source

pub fn dm( &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

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

Source§

impl Context

Presence shortcuts, for handlers that already hold a Context.

Source

pub fn set_presence( &self, status: Status, activity: impl Into<Option<Activity>>, )

Sets the bot’s status and activity (crate::presence::set).

Source

pub fn set_status_text(&self, text: impl Into<String>) -> Result<(), HostError>

Sets the bot’s custom status text (crate::presence::set_status_text).

§Errors

The host’s refusal.

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Context

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.