Struct PrivateChannel

Source
#[non_exhaustive]
pub struct PrivateChannel { pub id: ChannelId, pub last_message_id: Option<MessageId>, pub last_pin_timestamp: Option<Timestamp>, pub kind: ChannelType, pub recipient: User, }
Expand description

A Direct Message text channel with another user.

Discord docs.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§id: ChannelId

The unique Id of the private channel.

Can be used to calculate the first message’s creation date.

§last_message_id: Option<MessageId>

The Id of the last message sent.

§last_pin_timestamp: Option<Timestamp>

Timestamp of the last time a Message was pinned.

§kind: ChannelType

Indicator of the type of channel this is.

This should always be ChannelType::Private.

§recipient: User

The recipient to the private channel.

Implementations§

Source§

impl PrivateChannel

Source

pub async fn broadcast_typing(&self, http: impl AsRef<Http>) -> Result<()>

Broadcasts that the current user is typing to the recipient.

See ChannelId::broadcast_typing for more details.

Source

pub async fn create_reaction( &self, http: impl AsRef<Http>, message_id: impl Into<MessageId>, reaction_type: impl Into<ReactionType>, ) -> Result<()>

React to a Message with a custom Emoji or unicode character.

Message::react may be a more suited method of reacting in most cases.

§Errors

Returns Error::Http if the reaction cannot be added, or if a message with that Id does not exist.

Source

pub async fn delete(&self, http: impl AsRef<Http>) -> Result<PrivateChannel>

Deletes the channel. This does not delete the contents of the channel, and is equivalent to closing a private channel on the client, which can be re-opened.

Source

pub async fn delete_messages<T: AsRef<MessageId>>( &self, http: impl AsRef<Http>, message_ids: impl IntoIterator<Item = T>, ) -> Result<()>

Deletes all messages by Ids from the given vector in the channel.

The minimum amount of messages is 2 and the maximum amount is 100.

Requires the Manage Messages permission.

Note: Messages that are older than 2 weeks can’t be deleted using this method.

§Errors

Returns ModelError::BulkDeleteAmount if an attempt was made to delete either 0 or more than 100 messages.

Source

pub async fn delete_permission( &self, http: impl AsRef<Http>, permission_type: PermissionOverwriteType, ) -> Result<()>

Deletes all permission overrides in the channel from a member or role.

Note: Requires the Manage Channel permission.

Source

pub async fn delete_reaction( &self, http: impl AsRef<Http>, message_id: impl Into<MessageId>, user_id: Option<UserId>, reaction_type: impl Into<ReactionType>, ) -> Result<()>

Deletes the given Reaction from the channel.

Note: In private channels, the current user may only delete it’s own reactions.

§Errors

Returns Error::Http if the reaction is not from the current user.

Source

pub async fn edit_message( &self, cache_http: impl CacheHttp, message_id: impl Into<MessageId>, builder: EditMessage, ) -> Result<Message>

Edits a Message in the channel given its Id.

Message editing preserves all unchanged message data, with some exceptions for embeds and attachments.

Note: In most cases requires that the current user be the author of the message.

Refer to the documentation for EditMessage for information regarding content restrictions and requirements.

§Errors

See EditMessage::execute for a list of possible errors, and their corresponding reasons.

Source

pub fn is_nsfw(&self) -> bool

👎Deprecated: This always returns false

Determines if the channel is NSFW.

Source

pub async fn message( &self, cache_http: impl CacheHttp, message_id: impl Into<MessageId>, ) -> Result<Message>

Gets a message from the channel.

§Errors

Returns Error::Http if a message with that Id does not exist in this channel.

Source

pub async fn messages( &self, cache_http: impl CacheHttp, builder: GetMessages, ) -> Result<Vec<Message>>

Gets messages from the channel.

Note: If the user does not have the Read Message History permission, returns an empty Vec.

§Errors

Returns Error::Http if the current user lacks permission.

Source

pub fn name(&self) -> String

Returns “DM with $username#discriminator”.

Source

pub async fn reaction_users( &self, http: impl AsRef<Http>, message_id: impl Into<MessageId>, reaction_type: impl Into<ReactionType>, limit: Option<u8>, after: impl Into<Option<UserId>>, ) -> Result<Vec<User>>

Gets the list of Users who have reacted to a Message with a certain Emoji.

The default limit is 50 - specify otherwise to receive a different maximum number of users. The maximum that may be retrieve at a time is 100, if a greater number is provided then it is automatically reduced.

The optional after attribute is to retrieve the users after a certain user. This is useful for pagination.

§Errors

Returns Error::Http if a message with the given Id does not exist in the channel.

Source

pub async fn pin( &self, http: impl AsRef<Http>, message_id: impl Into<MessageId>, ) -> Result<()>

Pins a Message to the channel.

§Errors

Returns Error::Http if the number of pinned messages would exceed the 50 message limit.

Source

pub async fn pins(&self, http: impl AsRef<Http>) -> Result<Vec<Message>>

Retrieves the list of messages that have been pinned in the private channel.

Source

pub async fn say( &self, cache_http: impl CacheHttp, content: impl Into<String>, ) -> Result<Message>

Sends a message with just the given message content in the channel.

Note: Message content must be under 2000 unicode code points.

§Errors

Returns a ModelError::MessageTooLong if the content length is over the above limit. See CreateMessage::execute for more details.

Source

pub async fn send_files( self, cache_http: impl CacheHttp, files: impl IntoIterator<Item = CreateAttachment>, builder: CreateMessage, ) -> Result<Message>

Sends file(s) along with optional message contents.

Refer to ChannelId::send_files for examples and more information.

§Errors

See CreateMessage::execute for a list of possible errors, and their corresponding reasons.

Source

pub async fn send_message( &self, cache_http: impl CacheHttp, builder: CreateMessage, ) -> Result<Message>

Sends a message to the channel.

Refer to the documentation for CreateMessage for information regarding content restrictions and requirements.

§Errors

See CreateMessage::execute for a list of possible errors, and their corresponding reasons.

Source

pub fn start_typing(self, http: &Arc<Http>) -> Typing

Starts typing in the channel for an indefinite period of time.

Returns Typing that is used to trigger the typing. Typing::stop must be called on the returned struct to stop typing. Note that on some clients, typing may persist for a few seconds after Typing::stop is called. Typing is also stopped when the struct is dropped.

If a message is sent while typing is triggered, the user will stop typing for a brief period of time and then resume again until either Typing::stop is called or the struct is dropped.

This should rarely be used for bots, although it is a good indicator that a long-running command is still being processed.

§Examples
// Initiate typing (assuming http is `Arc<Http>` and `channel` is bound)
let typing = channel.start_typing(&http);

// Run some long-running process
long_process();

// Stop typing
typing.stop();
§Errors

May return Error::Http if the current user cannot send a direct message to this user.

Source

pub async fn unpin( &self, http: impl AsRef<Http>, message_id: impl Into<MessageId>, ) -> Result<()>

Unpins a Message in the channel given by its Id.

§Errors

Returns Error::Http if the current user lacks permission, if the message was deleted, or if the channel already has the limit of 50 pinned messages.

Trait Implementations§

Source§

impl Clone for PrivateChannel

Source§

fn clone(&self) -> PrivateChannel

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 PrivateChannel

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for PrivateChannel

Source§

fn default() -> PrivateChannel

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for PrivateChannel

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for PrivateChannel

Source§

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

Formats the private channel, displaying the recipient’s username.

Source§

impl From<&PrivateChannel> for ChannelId

Source§

fn from(private_channel: &PrivateChannel) -> ChannelId

Gets the Id of a private channel.

Source§

impl From<PrivateChannel> for ChannelId

Source§

fn from(private_channel: PrivateChannel) -> ChannelId

Gets the Id of a private channel.

Source§

impl Mentionable for PrivateChannel

Source§

fn mention(&self) -> Mention

Creates a Mention that will be able to notify or create a link to the item. Read more
Source§

impl Serialize for PrivateChannel

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

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

Source§

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,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

impl<T> MaybeSendSync for T