Movatterモバイル変換


[0]ホーム

URL:


Docs.rs

StructContext

Source
pub struct Context {    pub data:Arc<RwLock<TypeMap>>,    pub shard:ShardMessenger,    pub shard_id:ShardId,    pub http:Arc<Http>,    pub cache:Arc<Cache>,}
Available oncrate featureclient only.
Expand description

The context is a general utility struct provided on event dispatches.

The Context helps with dealing with the current “context” of the event dispatch. The contextalso acts as a general high-level interface over the associatedShard which receivedthe event, or the low-levelhttp module.

The context contains “shortcuts”, like for interacting with the shard. Methods likeSelf::set_activity will unlock the shard and perform an update for you to save a bit ofwork.

A context will only live for the event it was dispatched for. After the event handler finished,it is destroyed and will not be re-used.

Fields§

§data:Arc<RwLock<TypeMap>>

A clone ofClient::data. Refer to its documentation for more information.

§shard:ShardMessenger

The messenger to communicate with the shard runner.

§shard_id:ShardId

The ID of the shard this context is related to.

§http:Arc<Http>§cache:Arc<Cache>
Available oncrate featurecache only.

Implementations§

Source§

implContext

Source

pub fnonline(&self)

Available oncrate featuregateway only.

Sets the current user as beingOnline. This maintains the current activity.

§Examples

Set the current user to being online on the shard:

#[serenity::async_trait]implEventHandlerforHandler {async fnmessage(&self, ctx: Context, msg: Message) {ifmsg.content =="!online"{            ctx.online();        }    }}
Source

pub fnidle(&self)

Available oncrate featuregateway only.

Sets the current user as beingIdle. This maintains the current activity.

§Examples

Set the current user to being idle on the shard:

#[serenity::async_trait]implEventHandlerforHandler {async fnmessage(&self, ctx: Context, msg: Message) {ifmsg.content =="!idle"{            ctx.idle();        }    }}
Source

pub fndnd(&self)

Available oncrate featuregateway only.

Sets the current user as beingDoNotDisturb. This maintains the current activity.

§Examples

Set the current user to being Do Not Disturb on the shard:

#[serenity::async_trait]implEventHandlerforHandler {async fnmessage(&self, ctx: Context, msg: Message) {ifmsg.content =="!dnd"{            ctx.dnd();        }    }}
Source

pub fninvisible(&self)

Available oncrate featuregateway only.

Sets the current user as beingInvisible. This maintains the current activity.

§Examples

Set the current user to being invisible on the shard:

#[serenity::async_trait]implEventHandlerforHandler {async fnmessage(&self, ctx: Context, msg: Message) {ifmsg.content =="!invisible"{            ctx.invisible();        }    }}
Source

pub fnreset_presence(&self)

Available oncrate featuregateway only.

“Resets” the current user’s presence, by setting the activity toNone and the onlinestatus toOnline.

UseSelf::set_presence for fine-grained control over individual details.

§Examples

Reset the current user’s presence on the shard:

#[serenity::async_trait]implEventHandlerforHandler {async fnmessage(&self, ctx: Context, msg: Message) {ifmsg.content =="!reset_presence"{            ctx.reset_presence();        }    }}
Source

pub fnset_activity(&self, activity:Option<ActivityData>)

Available oncrate featuregateway only.

Sets the current activity.

§Examples

Create a command named~setgame that accepts a name of a game to be playing:

useserenity::gateway::ActivityData;#[serenity::async_trait]implEventHandlerforHandler {async fnmessage(&self, ctx: Context, msg: Message) {letmutargs = msg.content.splitn(2,' ');if let(Some("~setgame"),Some(game)) = (args.next(), args.next()) {            ctx.set_activity(Some(ActivityData::playing(game)));        }    }}
Source

pub fnset_presence(&self, activity:Option<ActivityData>, status:OnlineStatus)

Available oncrate featuregateway only.

Sets the current user’s presence, providing all fields to be passed.

§Examples

Setting the current user as having no activity and beingIdle:

#[serenity::async_trait]implEventHandlerforHandler {async fnready(&self, ctx: Context,_: Ready) {useserenity::model::user::OnlineStatus;        ctx.set_presence(None, OnlineStatus::Idle);    }}

Setting the current user as playing"Heroes of the Storm", while beingDoNotDisturb:

#[serenity::async_trait]implEventHandlerforHandler {async fnready(&self, context: Context,_: Ready) {useserenity::gateway::ActivityData;useserenity::model::user::OnlineStatus;letactivity = ActivityData::playing("Heroes of the Storm");letstatus = OnlineStatus::DoNotDisturb;        context.set_presence(Some(activity), status);    }}
Source

pub async fnget_application_emojis(&self) ->Result<Vec<Emoji>>

Gets all emojis for the current application.

§Errors

Returns an error if the Application ID is not known.

Source

pub async fnget_application_emoji(&self, emoji_id:EmojiId) ->Result<Emoji>

Gets information about an application emoji.

§Errors

Returns an error if the emoji does not exist.

Source

pub async fncreate_application_emoji( &self, name: &str, image: &str,) ->Result<Emoji>

Creates an application emoji with a name and base64-encoded image.

§Errors

SeeGuild::create_emoji for information about name and filesize requirements. Thismethod will error if said requirements are not met.

Source

pub async fnedit_application_emoji( &self, emoji_id:EmojiId, name: &str,) ->Result<Emoji>

Changes the name of an application emoji.

§Errors

Returns an error if the emoji does not exist.

Source

pub async fndelete_application_emoji(&self, emoji_id:EmojiId) ->Result<()>

Deletes an application emoji.

§Errors

Returns an error if the emoji does not exist.

Trait Implementations§

Source§

implAsRef<Arc<Cache>> forContext

Available oncrate featurecache only.
Source§

fnas_ref(&self) -> &Arc<Cache>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

implAsRef<Arc<Http>> forContext

Source§

fnas_ref(&self) -> &Arc<Http>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

implAsRef<Cache> forContext

Available oncrate featurecache only.
Source§

fnas_ref(&self) -> &Cache

Converts this type into a shared reference of the (usually inferred) input type.
Source§

implAsRef<Http> forContext

Source§

fnas_ref(&self) -> &Http

Converts this type into a shared reference of the (usually inferred) input type.
Source§

implAsRef<ShardMessenger> forContext

Available oncrate featuregateway only.
Source§

fnas_ref(&self) -> &ShardMessenger

Converts this type into a shared reference of the (usually inferred) input type.
Source§

implCacheHttp forContext

Available oncrate featurehttp only.
Source§

fnhttp(&self) -> &Http

Source§

fncache(&self) ->Option<&Arc<Cache>>

Available oncrate featurecache only.
Source§

implClone forContext

Source§

fnclone(&self) ->Context

Returns a duplicate of the value.Read more
1.0.0 ·Source§

fnclone_from(&mut self, source: &Self)

Performs copy-assignment fromsource.Read more
Source§

implDebug forContext

Source§

fnfmt(&self, f: &mutFormatter<'_>) ->Result

Formats the value using the given formatter.Read more

Auto Trait Implementations§

§

implFreeze forContext

§

impl !RefUnwindSafe forContext

§

implSend forContext

§

implSync forContext

§

implUnpin forContext

§

impl !UnwindSafe forContext

Blanket Implementations§

Source§

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

Source§

fntype_id(&self) ->TypeId

Gets theTypeId ofself.Read more
Source§

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

Source§

fnborrow(&self) ->&T

Immutably borrows from an owned value.Read more
Source§

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

Source§

fnborrow_mut(&mut self) ->&mut T

Mutably borrows from an owned value.Read more
Source§

impl<T>CloneDebuggableStorage for T

Source§

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

Source§

unsafe fnclone_to_uninit(&self, dest:*mutu8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment fromself todest.Read more
Source§

impl<T>CloneableStorage for T
where T:Any +Send +Sync +Clone,

Source§

impl<T>From<T> for T

Source§

fnfrom(t: T) -> T

Returns the argument unchanged.

Source§

impl<T>Instrument for T

Source§

fninstrument(self, span:Span) ->Instrumented<Self>

Instruments this type with the providedSpan, returning anInstrumented wrapper.Read more
Source§

fnin_current_span(self) ->Instrumented<Self>

Instruments this type with thecurrentSpan, returning anInstrumented wrapper.Read more
Source§

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

Source§

fninto(self) -> U

CallsU::from(self).

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

Source§

impl<T>Same for T

Source§

typeOutput = T

Should always beSelf
Source§

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

Source§

typeOwned = T

The resulting type after obtaining ownership.
Source§

fnto_owned(&self) -> T

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

fnclone_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§

typeError =Infallible

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

fntry_from(value: U) ->Result<T, <T asTryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

typeError = <U asTryFrom<T>>::Error

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

fntry_into(self) ->Result<U, <U asTryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T>VZip<V> for T
where V:MultiLane<T>,

Source§

fnvzip(self) -> V

Source§

impl<T>WithSubscriber for T

Source§

fnwith_subscriber<S>(self, subscriber: S) ->WithDispatch<Self>
where S:Into<Dispatch>,

Attaches the providedSubscriber to this type, returning aWithDispatch wrapper.Read more
Source§

fnwith_current_subscriber(self) ->WithDispatch<Self>

Attaches the currentdefaultSubscriber to this type, returning aWithDispatch wrapper.Read more
Source§

impl<T>DebuggableStorage for T
where T:Any +Send +Sync +Debug,

Source§

impl<T>ErasedDestructor for T
where T: 'static,


[8]ページ先頭

©2009-2025 Movatter.jp