0
0 комментариев

Доброго времени суток! Имеется небольшая проблема, а именно:

Есть callback кнопка, при нажатии на которую мой бот должен проверить, подписан ли участник на N группу.

    from telebot.types import ChatMember
 
    if callback_data.find('check_subscribe') != -1:
        group_id = '-242022020'
        check = bot.get_chat_member(group_id, chat_id) #chat_id - id пользователя
 
        if type(check) == ChatMember:
              mes = 'OK!'
              bot.send_message(chat_id, mes)
 
        elif type(check) != ChatMember:
              mes = 'Error!'
              bot.send_message(chat_id, mes)

В любом случае у меня возвращается OK , ну это понятно. Потому что ChatMember возвращает в любом случае.

Вот тут и начинается проблема, я не знаю какие шаги делать дальше для проверки, что имеется в этом объекте ChatMember

Вот исходиник класса (взятый из офф.репы на гитхабе)

class ChatMember(JsonDeserializable):
    @classmethod
    def de_json(cls, json_type):
        obj = cls.check_json(json_type)
        user = User.de_json(obj['user'])
        status = obj['status']
        until_date = obj.get('until_date')
        can_be_edited = obj.get('can_be_edited')
        can_change_info = obj.get('can_change_info')
        can_post_messages = obj.get('can_post_messages')
        can_edit_messages = obj.get('can_edit_messages')
        can_delete_messages = obj.get('can_delete_messages')
        can_invite_users = obj.get('can_invite_users')
        can_restrict_members = obj.get('can_restrict_members')
        can_pin_messages = obj.get('can_pin_messages')
        can_promote_members = obj.get('can_promote_members')
        can_send_messages = obj.get('can_send_messages')
        can_send_media_messages = obj.get('can_send_media_messages')
        can_send_other_messages = obj.get('can_send_other_messages')
        can_add_web_page_previews = obj.get('can_add_web_page_previews')
        return cls(user, status, until_date, can_be_edited, can_change_info, can_post_messages, can_edit_messages,
                   can_delete_messages, can_invite_users, can_restrict_members, can_pin_messages, can_promote_members,
                   can_send_messages, can_send_media_messages, can_send_other_messages, can_add_web_page_previews)
 
    def __init__(self, user, status, until_date, can_be_edited, can_change_info, can_post_messages, can_edit_messages,
                 can_delete_messages, can_invite_users, can_restrict_members, can_pin_messages, can_promote_members,
                 can_send_messages, can_send_media_messages, can_send_other_messages, can_add_web_page_previews):
        self.user = user
        self.status = status
        self.until_date = until_date
        self.can_be_edited = can_be_edited
        self.can_change_info = can_change_info
        self.can_post_messages = can_post_messages
        self.can_edit_messages = can_edit_messages
        self.can_delete_messages = can_delete_messages
        self.can_invite_users = can_invite_users
        self.can_restrict_members = can_restrict_members
        self.can_pin_messages = can_pin_messages
        self.can_promote_members = can_promote_members
        self.can_send_messages = can_send_messages
        self.can_send_media_messages = can_send_media_messages
        self.can_send_other_messages = can_send_other_messages
        self.can_add_web_page_previews = can_add_web_page_previews

Помогите пожалуйста!

Пытался делать вот такое

        if type(check) == ChatMember:
            if 'user' in ChatMember:
                mes = 'SUCESS!'
                bot.send_message(chat_id, mes)

Но получал >>> argument of type 'type' is not iterable

        if type(check) == ChatMember:
            if ChatMember['user'] == chat_id:
                mes = 'SUCESS!'
                bot.send_message(chat_id, mes)

>>> type' object is not subscriptable


Добавить комментарий