Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vk_api 5.103 #2

Open
Burfedd opened this issue Mar 18, 2020 · 0 comments
Open

vk_api 5.103 #2

Burfedd opened this issue Mar 18, 2020 · 0 comments

Comments

@Burfedd
Copy link

Burfedd commented Mar 18, 2020

В Callback API и LongPoll API у события message_new вместо { object: message } будет приходить { object: { message, client_info } }.

Описанный event listener больше не работает, так как по запросам напрямую к event.object.from_id или group_id возвращается None.
Код для предыдущих версий:

def start(self):
        for event in self.long_poll.listen():   # Слушаем сервер
            if event.type == VkBotEventType.MESSAGE_NEW:


                if event.object.from_id not in self.users:
                    self.users[event.object.from_id] = Commander()

                # Пришло новое сообщение
                if event.type == VkBotEventType.MESSAGE_NEW:
                       self.send_msg(event.object.peer_id,
                       self.users[event.object.from_id].input(event.object.text)) 

Код для версий 5.103 и выше:

def start(self):
        for event in self.long_poll.listen():   # Слушаем сервер
            if event.type == VkBotEventType.MESSAGE_NEW:

                if event.object.message["from_id"] not in self.users:
                    self.users[event.object.message["from_id"]] = Commander()

                # Пришло новое сообщение
                if event.type == VkBotEventType.MESSAGE_NEW:

                    self.send_msg(event.object.message["peer_id"],
                                  self.users[event.object.message["from_id"]].input(event.object.message["text"]))

Спасибо за статью на хабре, очень полезно!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant