Skip to main content

ChatMemberKind

Enum ChatMemberKind 

Source
pub enum ChatMemberKind {
    Owner(Owner),
    Administrator(Administrator),
    Member(Member),
    Restricted(Restricted),
    Left,
    Banned(Banned),
}

Variants§

§

Owner(Owner)

§

Administrator(Administrator)

§

Member(Member)

§

Restricted(Restricted)

§

Left

§

Banned(Banned)

Implementations§

Source§

impl ChatMemberKind

Simple methods for checking a user status.

Source

pub fn status(&self) -> ChatMemberStatus

Returns chat member status.

Source

pub fn is_owner(&self) -> bool

Returns true if the user is the owner of the given chat.

Source

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.

Source

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.

Source

pub fn is_restricted(&self) -> bool

Returns true if the user is restricted in the given chat.

Source

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?
examples/chat_member_updates.rs (line 32)
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}
Source

pub fn is_banned(&self) -> bool

Returns true if the user is banned in the given chat.

Source§

impl ChatMemberKind

Compound methods for checking a user status.

Source

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.

Source

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?
examples/chat_member_updates.rs (line 32)
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}
Source§

impl ChatMemberKind

Source

pub fn custom_title(&self) -> Option<&str>

Source

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.

Source

pub fn until_date(&self) -> Option<UntilDate>

Source§

impl ChatMemberKind

Methods for checking admin privileges.

Source

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.

Source

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_chat privilege.

Returns false otherwise.

Source

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_messages privilege.

Returns false otherwise.

Source

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_messages privilege.

Returns false otherwise.

Source

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_messages privilege.

Returns false otherwise.

Source

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_stories privilege.

Returns false otherwise.

Source

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_stories privilege.

Returns false otherwise.

Source

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_stories privilege.

Returns false otherwise.

Source

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_chats privilege.

Returns false otherwise.

Source

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_members privilege.

Returns false otherwise.

Examples found in repository?
examples/admin.rs (line 129)
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}
Source

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_members privilege.

Returns false otherwise.

Trait Implementations§

Source§

impl Clone for ChatMemberKind

Source§

fn clone(&self) -> ChatMemberKind

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ChatMemberKind

Source§

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

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

impl<'de> Deserialize<'de> for ChatMemberKind

Source§

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

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

impl Eq for ChatMemberKind

Source§

impl Hash for ChatMemberKind

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ChatMemberKind

Source§

fn eq(&self, other: &ChatMemberKind) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ChatMemberKind

Source§

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

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ChatMemberKind

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> Erasable for T

Source§

const ACK_1_1_0: bool = true

Available on non-enforce_1_1_0_semantics only.
Whether this implementor has acknowledged the 1.1.0 update to unerase’s documented implementation requirements. Read more
Source§

unsafe fn unerase(this: NonNull<Erased>) -> NonNull<T>

Unerase this erased pointer. Read more
Source§

fn erase(this: NonNull<Self>) -> NonNull<Erased>

Turn this erasable pointer into an erased pointer. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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