pub struct ShardMessenger { /* private fields */ }
client
and gateway
only.Expand description
A lightweight wrapper around an mpsc sender.
This is used to cleanly communicate with a shard’s respective
ShardRunner
. This can be used for actions such as setting the activity
via Self::set_activity
or shutting down via Self::shutdown_clean
.
Implementations
sourceimpl ShardMessenger
impl ShardMessenger
sourcepub fn new(tx: Sender<InterMessage>) -> Self
pub fn new(tx: Sender<InterMessage>) -> Self
Creates a new shard messenger.
If you are using the Client
, you do not need to do this.
sourcepub fn chunk_guild(
&self,
guild_id: GuildId,
limit: Option<u16>,
filter: ChunkGuildFilter,
nonce: Option<String>
)
pub fn chunk_guild(
&self,
guild_id: GuildId,
limit: Option<u16>,
filter: ChunkGuildFilter,
nonce: Option<String>
)
Requests that one or multiple Guild
s be chunked.
This will ask the gateway to start sending member chunks for large guilds (250 members+). If a guild is over 250 members, then a full member list will not be downloaded, and must instead be requested to be sent in “chunks” containing members.
Member chunks are sent as the Event::GuildMembersChunk
event. Each
chunk only contains a partial amount of the total members.
If the cache
feature is enabled, the cache will automatically be
updated with member chunks.
Examples
Chunk a single guild by Id, limiting to 2000 Member
s, and not
specifying a query parameter:
use serenity::model::id::GuildId;
shard.chunk_guild(GuildId(81384788765712384), Some(2000), ChunkGuildFilter::None, None);
Chunk a single guild by Id, limiting to 20 members, specifying a
query parameter of "do"
and a nonce of "request"
:
use serenity::model::id::GuildId;
shard.chunk_guild(
GuildId(81384788765712384),
Some(20),
ChunkGuildFilter::Query("do".to_owned()),
Some("request"),
);
sourcepub fn set_activity(&self, activity: Option<Activity>)
pub fn set_activity(&self, activity: Option<Activity>)
Sets the user’s current activity, if any.
Other presence settings are maintained.
Examples
Setting the current activity to playing "Heroes of the Storm"
:
use serenity::model::gateway::Activity;
shard.set_activity(Some(Activity::playing("Heroes of the Storm")));
sourcepub fn set_presence(&self, activity: Option<Activity>, status: OnlineStatus)
pub fn set_presence(&self, activity: Option<Activity>, status: OnlineStatus)
Sets the user’s full presence information.
Consider using the individual setters if you only need to modify one of these.
Examples
Set the current user as playing "Heroes of the Storm"
and being
online:
use serenity::model::gateway::Activity;
use serenity::model::user::OnlineStatus;
let activity = Activity::playing("Heroes of the Storm");
shard.set_presence(Some(activity), OnlineStatus::Online);
sourcepub fn set_status(&self, online_status: OnlineStatus)
pub fn set_status(&self, online_status: OnlineStatus)
Sets the user’s current online status.
Note that Offline
is not a valid online status, so it is
automatically converted to Invisible
.
Other presence settings are maintained.
Examples
Setting the current online status for the shard to DoNotDisturb
.
use serenity::model::user::OnlineStatus;
shard.set_status(OnlineStatus::DoNotDisturb);
sourcepub fn shutdown_clean(&self)
pub fn shutdown_clean(&self)
Shuts down the websocket by attempting to cleanly close the connection.
sourcepub fn websocket_message(&self, message: Message)
pub fn websocket_message(&self, message: Message)
Sends a raw message over the WebSocket.
The given message is not mutated in any way, and is sent as-is.
You should only use this if you know what you’re doing. If you’re
wanting to, for example, send a presence update, prefer the usage of
the Self::set_presence
method.
sourcepub fn send_to_shard(
&self,
msg: ShardRunnerMessage
) -> Result<(), TrySendError<InterMessage>>
pub fn send_to_shard(
&self,
msg: ShardRunnerMessage
) -> Result<(), TrySendError<InterMessage>>
sourcepub fn set_event_filter(&self, collector: EventFilter)
Available on crate feature collector
only.
pub fn set_event_filter(&self, collector: EventFilter)
collector
only.Sets a new filter for an event collector.
sourcepub fn set_message_filter(&self, collector: MessageFilter)
Available on crate feature collector
only.
pub fn set_message_filter(&self, collector: MessageFilter)
collector
only.Sets a new filter for a message collector.
sourcepub fn set_reaction_filter(&self, collector: ReactionFilter)
Available on crate feature collector
only.
pub fn set_reaction_filter(&self, collector: ReactionFilter)
collector
only.Sets a new filter for a reaction collector.
sourcepub fn set_component_interaction_filter(
&self,
collector: ComponentInteractionFilter
)
Available on crate feature collector
only.
pub fn set_component_interaction_filter(
&self,
collector: ComponentInteractionFilter
)
collector
only.Sets a new filter for a component interaction collector.
sourcepub fn set_modal_interaction_filter(&self, collector: ModalInteractionFilter)
Available on crate feature collector
only.
pub fn set_modal_interaction_filter(&self, collector: ModalInteractionFilter)
collector
only.Sets a new filter for a modal interaction collector.
Trait Implementations
sourceimpl AsRef<ShardMessenger> for ShardMessenger
impl AsRef<ShardMessenger> for ShardMessenger
sourcefn as_ref(&self) -> &ShardMessenger
fn as_ref(&self) -> &ShardMessenger
Converts this type into a shared reference of the (usually inferred) input type.
sourceimpl AsRef<ShardMessenger> for ShardRunnerInfo
impl AsRef<ShardMessenger> for ShardRunnerInfo
sourcefn as_ref(&self) -> &ShardMessenger
fn as_ref(&self) -> &ShardMessenger
Converts this type into a shared reference of the (usually inferred) input type.
sourceimpl AsRef<ShardMessenger> for Context
impl AsRef<ShardMessenger> for Context
sourcefn as_ref(&self) -> &ShardMessenger
fn as_ref(&self) -> &ShardMessenger
Converts this type into a shared reference of the (usually inferred) input type.
sourceimpl Clone for ShardMessenger
impl Clone for ShardMessenger
sourcefn clone(&self) -> ShardMessenger
fn clone(&self) -> ShardMessenger
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl !RefUnwindSafe for ShardMessenger
impl Send for ShardMessenger
impl Sync for ShardMessenger
impl Unpin for ShardMessenger
impl !UnwindSafe for ShardMessenger
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more