N
N
Nagga2021-01-25 23:18:44
Python
Nagga, 2021-01-25 23:18:44

How to add a user to a VK conversation (python bot)?

I can not add a person to the VK conversation. He is subscribed to the group, I enter /add 151315, where 151315 is his ID and the bot gives an error:

vk.messages.addChatUser(chat_id = id, user_id = member_id)
  File "C:\Users\Nagga\AppData\Local\Programs\Python\Python38\lib\site-packages\vk_api\vk_api.py", line 696, in __call__
    return self._vk.method(self._method, kwargs)
  File "C:\Users\Nagga\AppData\Local\Programs\Python\Python38\lib\site-packages\vk_api\vk_api.py", line 656, in method
    raise error
vk_api.exceptions.ApiError: [27] Group authorization failed: method is unavailable with group auth.

import vk_api
from vk_api.utils import get_random_id
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType

token_vk = 'мой токен'
autorizate = vk_api.VkApi(token = token_vk)
longpoll = VkBotLongPoll(autorizate, group_id = 201584840)
vk = autorizate.get_api()

while True:
    for event in longpoll.listen():
        if event.type == VkBotEventType.MESSAGE_NEW and event.from_chat and event.message.get('text'):
            msg = event.message.get('text')
            id = event.chat_id
            uid = event.message.get('from_id')
            if msg.split(' ')[0] == '/add':
                try:
                    member_id = int(msg.split(' ')[1])
                    vk.messages.addChatUser(chat_id = id, user_id = member_id)
                except:
                    vk.messages.send(message = 'Error.', random_id = get_random_id(), chat_id = id)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-01-25
@Nagga

Written,

method is unavailable with group auth

The method is not available through group authorization.
https://vk.com/dev/messages.addChatUser
This method can be called with a user access key obtained in the Standalone application via Implicit Flow. Permissions required: messages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question