pub struct ChatMember {
pub user: User,
pub kind: ChatMemberKind,
}Expand description
This object contains information about one member of the chat.
Fields§
§user: UserInformation about the user.
kind: ChatMemberKindThe member’s status in the chat.
Methods from Deref<Target = ChatMemberKind>§
Sourcepub fn status(&self) -> ChatMemberStatus
pub fn status(&self) -> ChatMemberStatus
Returns chat member status.
Sourcepub fn is_administrator(&self) -> bool
pub fn is_administrator(&self) -> bool
Returns true if the user is an administrator of the given chat.
Note: this function doesn’t return true if the user is the
owner of the given chat. See also: is_privileged.
Sourcepub fn is_member(&self) -> bool
pub fn is_member(&self) -> bool
Returns true if the user is a common member of the given chat.
⚠️ Don’t confuse this with is_present. This method merely checks
for ChatMemberKind::Member variant which is not enough to determine
if the user is joinned to the chat. Use is_present for that instead.
Sourcepub fn is_restricted(&self) -> bool
pub fn is_restricted(&self) -> bool
Returns true if the user is restricted in the given chat.
Sourcepub fn is_left(&self) -> bool
pub fn is_left(&self) -> bool
Returns true if the user left the given chat.
⚠️ Don’t confuse this with is_present. This method merely checks
for ChatMemberKind::Left variant which is not enough to determine
if the user is joinned to the chat. Use is_present for that instead.
Examples found in repository?
16async fn main() -> ResponseResult<()> {
17 pretty_env_logger::init();
18
19 // We specify default parse mode to be `Html`, so that later we can use
20 // `html::user_mention`
21 let bot = teloxide::Bot::from_env().parse_mode(ParseMode::Html);
22
23 // Create a handler for our bot, that will process updates from Telegram
24 let handler = dptree::entry()
25 .inspect(|u: Update| {
26 eprintln!("{u:#?}"); // Print the update to the console with inspect
27 })
28 .branch(
29 Update::filter_chat_member()
30 .branch(
31 dptree::filter(|m: ChatMemberUpdated| {
32 m.old_chat_member.is_left() && m.new_chat_member.is_present()
33 })
34 .endpoint(new_chat_member),
35 )
36 .branch(
37 dptree::filter(|m: ChatMemberUpdated| {
38 m.old_chat_member.is_present() && m.new_chat_member.is_left()
39 })
40 .endpoint(left_chat_member),
41 ),
42 );
43
44 // Create a dispatcher for our bot
45 Dispatcher::builder(bot, handler).enable_ctrlc_handler().build().dispatch().await;
46
47 Ok(())
48}Sourcepub fn is_privileged(&self) -> bool
pub fn is_privileged(&self) -> bool
Returns true if the user is privileged in the given chat. i.e. if the
user is either the owner or an administrator in the given chat.
Sourcepub fn is_present(&self) -> bool
pub fn is_present(&self) -> bool
Returns true if the user is currently present in the chat. i.e. if the
user hasn’t left or been banned. It also returns false if the
user left the chat, but was restricted.
Examples found in repository?
16async fn main() -> ResponseResult<()> {
17 pretty_env_logger::init();
18
19 // We specify default parse mode to be `Html`, so that later we can use
20 // `html::user_mention`
21 let bot = teloxide::Bot::from_env().parse_mode(ParseMode::Html);
22
23 // Create a handler for our bot, that will process updates from Telegram
24 let handler = dptree::entry()
25 .inspect(|u: Update| {
26 eprintln!("{u:#?}"); // Print the update to the console with inspect
27 })
28 .branch(
29 Update::filter_chat_member()
30 .branch(
31 dptree::filter(|m: ChatMemberUpdated| {
32 m.old_chat_member.is_left() && m.new_chat_member.is_present()
33 })
34 .endpoint(new_chat_member),
35 )
36 .branch(
37 dptree::filter(|m: ChatMemberUpdated| {
38 m.old_chat_member.is_present() && m.new_chat_member.is_left()
39 })
40 .endpoint(left_chat_member),
41 ),
42 );
43
44 // Create a dispatcher for our bot
45 Dispatcher::builder(bot, handler).enable_ctrlc_handler().build().dispatch().await;
46
47 Ok(())
48}Sourcepub fn custom_title(&self) -> Option<&str>
pub fn custom_title(&self) -> Option<&str>
Getter for Administrator::custom_title and Owner::custom_title
fields.
Sourcepub fn is_anonymous(&self) -> bool
pub fn is_anonymous(&self) -> bool
Returns true if the user’s presence in the chat is hidden.
I.e. returns true if the user is the owner of the chat or an
administrator in the chat and has the can_manage_chat privilege.
Returns false otherwise.
Sourcepub fn until_date(&self) -> Option<UntilDate>
pub fn until_date(&self) -> Option<UntilDate>
Getter for Restricted::until_date, Banned::until_date and
Member::until_date fields.
Sourcepub fn can_be_edited(&self) -> bool
pub fn can_be_edited(&self) -> bool
Returns true if the user is an administrator in the given chat and the
bot is allowed to edit administrator privileges of that user.
Sourcepub fn can_manage_chat(&self) -> bool
pub fn can_manage_chat(&self) -> bool
Returns true if the user can access the chat event log, chat
statistics, message statistics in channels, see channel members, see
anonymous administrators in supergroups and ignore slow mode. Implied by
any other administrator privilege.
I.e. returns true if the user
- is the owner of the chat
- is an administrator in the given chat and has
can_manage_chatprivilege.
Returns false otherwise.
Sourcepub fn can_post_messages(&self) -> bool
pub fn can_post_messages(&self) -> bool
Returns true if the user can post in the channel, channels only.
I.e. returns true if the user
- is the owner of the chat (even if the chat is not a channel)
- is an administrator in the given chat and has
can_post_messagesprivilege.
Returns false otherwise.
Sourcepub fn can_edit_messages(&self) -> bool
pub fn can_edit_messages(&self) -> bool
Returns true if the user can edit messages of other users and can pin
messages, channels only.
I.e. returns true if the user
- is the owner of the chat (even if the chat is not a channel)
- is an administrator in the given chat and has the
can_edit_messagesprivilege.
Returns false otherwise.
Sourcepub fn can_delete_messages(&self) -> bool
pub fn can_delete_messages(&self) -> bool
Returns true if the user can delete messages of other users.
I.e. returns true if the user
- is the owner of the chat
- is an administrator in the given chat and has the
can_delete_messagesprivilege.
Returns false otherwise.
Sourcepub fn can_post_stories(&self) -> bool
pub fn can_post_stories(&self) -> bool
Returns true if the administrator can post stories to the chat.
I.e. returns true if the user
- is the owner of the chat (even if the chat is not a channel)
- is an administrator in the given chat and has
can_post_storiesprivilege.
Returns false otherwise.
Sourcepub fn can_edit_stories(&self) -> bool
pub fn can_edit_stories(&self) -> bool
Returns true if the administrator can edit stories posted by other
users.
I.e. returns true if the user
- is the owner of the chat (even if the chat is not a channel)
- is an administrator in the given chat and has the
can_edit_storiesprivilege.
Returns false otherwise.
Sourcepub fn can_delete_stories(&self) -> bool
pub fn can_delete_stories(&self) -> bool
Returns true if the administrator can delete stories posted by other
users.
I.e. returns true if the user
- is the owner of the chat
- is an administrator in the given chat and has the
can_delete_storiesprivilege.
Returns false otherwise.
Sourcepub fn can_manage_video_chats(&self) -> bool
pub fn can_manage_video_chats(&self) -> bool
Returns true if the user can manage video chats.
I.e. returns true if the user
- is the owner of the chat
- is an administrator in the given chat and has the
can_manage_video_chatsprivilege.
Returns false otherwise.
Sourcepub fn can_restrict_members(&self) -> bool
pub fn can_restrict_members(&self) -> bool
Returns true if the user can restrict, ban or unban chat members.
I.e. returns true if the user
- is the owner of the chat
- is an administrator in the given chat and has the
can_restrict_membersprivilege.
Returns false otherwise.
Examples found in repository?
116async fn sender_can_restrict<E, F>(
117 msg: &Message,
118 get_member: impl FnOnce(ChatId, UserId) -> F,
119) -> bool
120where
121 F: Future<Output = Result<ChatMember, E>>,
122 E: std::fmt::Display,
123{
124 // Messages sent on behalf of chats can include a synthetic `from` user.
125 let Some(sender) = msg.from.as_ref().filter(|_| msg.sender_chat.is_none()) else {
126 return false;
127 };
128 match get_member(msg.chat.id, sender.id).await {
129 Ok(member) => member.kind.can_restrict_members(),
130 Err(err) => {
131 log::warn!("Could not verify moderation permissions in {}: {err}", msg.chat.id);
132 false
133 }
134 }
135}Sourcepub fn can_promote_members(&self) -> bool
pub fn can_promote_members(&self) -> bool
Returns true if the user can add new administrators with a subset of
his own privileges or demote administrators that he has promoted,
directly or indirectly (promoted by administrators that were appointed
by the user).
I.e. returns true if the user
- is the owner of the chat (even if the chat is not a channel)
- is an administrator in the given chat and has the
can_promote_membersprivilege.
Returns false otherwise.
Trait Implementations§
Source§impl Clone for ChatMember
impl Clone for ChatMember
Source§fn clone(&self) -> ChatMember
fn clone(&self) -> ChatMember
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ChatMember
impl Debug for ChatMember
Source§impl Deref for ChatMember
This allows calling ChatMemberKind’s methods directly on ChatMember.
impl Deref for ChatMember
This allows calling ChatMemberKind’s methods directly on ChatMember.
use teloxide_core::types::ChatMember;
let member: ChatMember = todo!();
let _ = member.status();
let _ = member.kind.status();Source§type Target = ChatMemberKind
type Target = ChatMemberKind
Source§impl<'de> Deserialize<'de> for ChatMember
impl<'de> Deserialize<'de> for ChatMember
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ChatMember, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ChatMember, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for ChatMember
Source§impl Hash for ChatMember
impl Hash for ChatMember
Source§impl PartialEq for ChatMember
impl PartialEq for ChatMember
Source§impl Serialize for ChatMember
impl Serialize for ChatMember
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for ChatMember
Auto Trait Implementations§
impl Forget for ChatMember
impl Freeze for ChatMember
impl Move for ChatMember
impl RefUnwindSafe for ChatMember
impl Send for ChatMember
impl Sync for ChatMember
impl Unpin for ChatMember
impl UnsafeUnpin for ChatMemberwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
NonZeroI32Inner: UnsafeUnpin,
Utc: UnsafeUnpin,
impl UnwindSafe for ChatMember
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Erasable for T
impl<T> Erasable for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more