pub struct Context {
pub http: Arc<HttpClient>,
pub cache: Arc<InMemoryCache>,
pub shard: Arc<Shard>,
pub interaction: Option<Arc<Interaction<'static>>>,
pub has_responded: Arc<RwLock<bool>>,
}Expand description
Context for a Slash Command execution.
Fields§
§http: Arc<HttpClient>§cache: Arc<InMemoryCache>§shard: Arc<Shard>§interaction: Option<Arc<Interaction<'static>>>§has_responded: Arc<RwLock<bool>>Whether the interaction has been deferred or replied to.
Implementations§
Source§impl Context
impl Context
pub fn new( http: Arc<HttpClient>, cache: Arc<InMemoryCache>, shard: Arc<Shard>, interaction: Option<Interaction<'static>>, ) -> Self
Sourcepub async fn defer(
&self,
ephemeral: bool,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn defer( &self, ephemeral: bool, ) -> Result<(), Box<dyn Error + Send + Sync>>
Defer the interaction.
This sends a “Thinking…” state (Opcode 5) to discord. You must call this within 3 seconds if your task takes long.
Sourcepub async fn reply(
&self,
content: impl Into<String>,
) -> Result<Message<'static>, Box<dyn Error + Send + Sync>>
pub async fn reply( &self, content: impl Into<String>, ) -> Result<Message<'static>, Box<dyn Error + Send + Sync>>
Reply to the command.
This smarter method checks if we have deferred.
If NOT deferred -> calls create_interaction_response
If DEFERRED -> calls edit_original_interaction_response
This solves the “3 second rule” complexity for the user!
Sourcepub async fn reply_embed(
&self,
embed: impl Into<Embed<'static>>,
) -> Result<Message<'static>, Box<dyn Error + Send + Sync>>
pub async fn reply_embed( &self, embed: impl Into<Embed<'static>>, ) -> Result<Message<'static>, Box<dyn Error + Send + Sync>>
Reply with an embed (discord.js-style).
Sourcepub async fn reply_ephemeral(
&self,
content: impl Into<String>,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn reply_ephemeral( &self, content: impl Into<String>, ) -> Result<(), Box<dyn Error + Send + Sync>>
Reply with an ephemeral message (only visible to user).
Sourcepub async fn edit_reply(
&self,
content: impl Into<String>,
) -> Result<Message<'static>, Box<dyn Error + Send + Sync>>
pub async fn edit_reply( &self, content: impl Into<String>, ) -> Result<Message<'static>, Box<dyn Error + Send + Sync>>
Edit the original interaction response.
Sourcepub async fn followup(
&self,
content: impl Into<String>,
) -> Result<Message<'static>, Box<dyn Error + Send + Sync>>
pub async fn followup( &self, content: impl Into<String>, ) -> Result<Message<'static>, Box<dyn Error + Send + Sync>>
Send a follow-up message.
Sourcepub fn channel_id(&self) -> Option<Snowflake>
pub fn channel_id(&self) -> Option<Snowflake>
Get the channel ID.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl !UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more