pub struct UserId(/* private fields */);
Expand description
An identifier for a User
Implementations§
Source§impl UserId
impl UserId
Sourcepub async fn create_dm_channel(
self,
cache_http: impl CacheHttp,
) -> Result<PrivateChannel>
pub async fn create_dm_channel( self, cache_http: impl CacheHttp, ) -> Result<PrivateChannel>
Creates a direct message channel between the current user and the user. This can also retrieve the channel if one already exists.
§Errors
Returns Error::Http
if a User
with that UserId
does not exist, or is otherwise
unavailable.
May also return an Error::Json
if there is an error in deserializing the channel data
returned by the Discord API.
Sourcepub async fn direct_message(
self,
cache_http: impl CacheHttp,
builder: CreateMessage,
) -> Result<Message>
pub async fn direct_message( self, cache_http: impl CacheHttp, builder: CreateMessage, ) -> Result<Message>
Sends a message to a user through a direct message channel. This is a channel that can only be accessed by you and the recipient.
§Examples
When a user sends a message with a content of "~help"
, DM the author a help message
use serenity::builder::CreateMessage;
#[serenity::async_trait]
impl EventHandler for Handler {
async fn message(&self, ctx: Context, msg: Message) {
if msg.content == "~help" {
let builder = CreateMessage::new().content("Helpful info here.");
if let Err(why) = msg.author.id.direct_message(&ctx, builder).await {
println!("Err sending help: {why:?}");
let _ = msg.reply(&ctx, "There was an error DMing you help.").await;
};
}
}
}
§Errors
Returns a ModelError::MessagingBot
if the user being direct messaged is a bot user.
May also return an Error::Http
if the user cannot be sent a direct message.
Returns an Error::Json
if there is an error deserializing the API response.
Sourcepub async fn dm(
self,
cache_http: impl CacheHttp,
builder: CreateMessage,
) -> Result<Message>
pub async fn dm( self, cache_http: impl CacheHttp, builder: CreateMessage, ) -> Result<Message>
This is an alias of Self::direct_message
.
Sourcepub fn to_user_cached(self, cache: &impl AsRef<Cache>) -> Option<UserRef<'_>>
pub fn to_user_cached(self, cache: &impl AsRef<Cache>) -> Option<UserRef<'_>>
Attempts to find a User
by its Id in the cache.
Sourcepub async fn to_user(self, cache_http: impl CacheHttp) -> Result<User>
pub async fn to_user(self, cache_http: impl CacheHttp) -> Result<User>
First attempts to find a User
by its Id in the cache, upon failure requests it via the
REST API.
Note: If the cache is not enabled, REST API will be used only.
Note: If the cache is enabled, you might want to enable the temp_cache
feature to
cache user data retrieved by this function for a short duration.
§Errors
May return an Error::Http
if a User
with that UserId
does not exist, or
otherwise cannot be fetched.
May also return an Error::Json
if there is an error in deserializing the user.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for UserId
impl<'de> Deserialize<'de> for UserId
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<CommandPermissionId> for UserId
impl From<CommandPermissionId> for UserId
Source§fn from(id: CommandPermissionId) -> Self
fn from(id: CommandPermissionId) -> Self
Source§impl From<NonZero<u64>> for UserId
impl From<NonZero<u64>> for UserId
Source§fn from(id: NonZeroU64) -> UserId
fn from(id: NonZeroU64) -> UserId
Source§impl From<UserId> for CommandPermissionId
impl From<UserId> for CommandPermissionId
Source§impl From<UserId> for NonZeroI64
impl From<UserId> for NonZeroI64
Source§fn from(id: UserId) -> NonZeroI64
fn from(id: UserId) -> NonZeroI64
Source§impl From<UserId> for NonZeroU64
impl From<UserId> for NonZeroU64
Source§fn from(id: UserId) -> NonZeroU64
fn from(id: UserId) -> NonZeroU64
Source§impl Ord for UserId
impl Ord for UserId
Source§impl PartialOrd for UserId
impl PartialOrd for UserId
impl Copy for UserId
impl Eq for UserId
impl StructuralPartialEq for UserId
Auto Trait Implementations§
impl Freeze for UserId
impl RefUnwindSafe for UserId
impl Send for UserId
impl Sync for UserId
impl Unpin for UserId
impl UnwindSafe for UserId
Blanket Implementations§
Source§impl<T> ArgumentConvert for Twhere
T: FromStr,
impl<T> ArgumentConvert for Twhere
T: FromStr,
Source§fn convert<'life0, 'async_trait>(
__arg0: impl CacheHttp + 'async_trait,
__arg1: Option<GuildId>,
__arg2: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<T, <T as ArgumentConvert>::Err>> + Send + 'async_trait>>where
'life0: 'async_trait,
T: 'async_trait,
fn convert<'life0, 'async_trait>(
__arg0: impl CacheHttp + 'async_trait,
__arg1: Option<GuildId>,
__arg2: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<T, <T as ArgumentConvert>::Err>> + Send + 'async_trait>>where
'life0: 'async_trait,
T: 'async_trait,
s
as a command parameter of this type.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
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.