pub struct ShardMessenger { /* private fields */ }
Available on crate feature gateway only.
Expand description

A handle to a ShardRunner.

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§

source§

impl ShardMessenger

source

pub fn new(shard: &ShardRunner) -> Self

Creates a new shard messenger.

If you are using the Client, you do not need to do this.

source

pub fn chunk_guild( &self, guild_id: GuildId, limit: Option<u16>, presences: bool, filter: ChunkGuildFilter, nonce: Option<String> )

Requests that one or multiple Guilds 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 Members, and not specifying a query parameter:

use serenity::model::id::GuildId;

shard.chunk_guild(GuildId::new(81384788765712384), Some(2000), false, 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::new(81384788765712384),
    Some(20),
    false,
    ChunkGuildFilter::Query("do".to_owned()),
    Some("request"),
);
source

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

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::gateway::ActivityData;

shard.set_activity(Some(ActivityData::playing("Heroes of the Storm")));
source

pub fn set_presence(&self, activity: Option<ActivityData>, 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::gateway::ActivityData;
use serenity::model::user::OnlineStatus;

let activity = ActivityData::playing("Heroes of the Storm");
shard.set_presence(Some(activity), OnlineStatus::Online);
source

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);
source

pub fn shutdown_clean(&self)

Shuts down the websocket by attempting to cleanly close the connection.

source

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.

source

pub fn send_to_shard(&self, msg: ShardRunnerMessage)

Sends a message to the shard.

source

pub fn add_collector(&self, collector: CollectorCallback)

Available on crate feature collector only.

Trait Implementations§

source§

impl AsRef<ShardMessenger> for Context

Available on crate feature client only.
source§

fn as_ref(&self) -> &ShardMessenger

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

impl AsRef<ShardMessenger> for ShardMessenger

source§

fn as_ref(&self) -> &ShardMessenger

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

impl AsRef<ShardMessenger> for ShardRunnerInfo

source§

fn as_ref(&self) -> &ShardMessenger

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

impl Clone for ShardMessenger

source§

fn clone(&self) -> ShardMessenger

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for ShardMessenger

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> CloneDebuggableStorage for T

source§

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

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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

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

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

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