A
A
Alexander2018-08-25 07:12:57
Python
Alexander, 2018-08-25 07:12:57

How to send messages to the chat using the vk library?

I am writing a bot using the vk library .
Using this code, the bot wrote messages, but it could only send messages to a specific person, not to a chat (in the chat, it simply did not respond to commands):

api.messages.send(access_token=config.token, user_id=str(user_id), message=msg)

Obviously, you need to change the user_id to something else, and I changed it to peer_id:
api.messages.send(access_token=config.token, peer_id=str(peer_id), message=msg)

But when the bot tries to send a message (already responding to commands in the chat), an exception vk.exceptions.VkAPIError: 100 is thrown. One of the parameters specified was missing or invalid: peer_id is accepted only from version 5.38. request_params = {'oauth': '1', 'method': 'messages.send', 'v': '5.8', 'peer_id': '2000000001'} . I am using VK API 5.80
Just in case, here is the json that comes when I send a message to the chat with the bot
{'type': 'message_new', 'object': {'date': 1535167265, 'from_id': 139588086, 'id': 0, 'out': 0, 'peer_id': 2000000001, 'text': 'TEST', 'conversation_message_id': 24, 'fwd_messages': [], 'important': False, 'random_id': 0, 'attachments': [], 'is_hidden': False}, 'group_id': 170490539}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Helow19274, 2018-08-25
@AlexNineteen

You have version 5.8, not 5.80

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question