Answer the question
In order to leave comments, you need to log in
How to call messages.removeChatUser method?
An error occurs when I try to kick a user.
Screenshots are attached.
Code:
import random
from vk_api import VkApi
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from vk_api.utils import get_random_id
def main() -> None:
vk_session = VkApi(token= 'my token')
long_poll = VkBotLongPoll(vk_session, 'adi groups ')
vk = vk_session.get_api()
users = vk.users
for event in long_poll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
peer_id = event.obj['peer_id']
message = event.obj[' text'].lower()
if message == 'ku':
vk.messages.send(
peer_id=peer_id,
message='Hi!',
random_id=get_random_id(),
)
if event.object.text == "kick":
vk.method("messages.removeChatUser", {"chat_id" : event.object.peer_id-2000000000, "user_id": event.user_id, "member_id": "user_id", "random_id": random.randint(1, 2147483647)})
if __name__ == '__main__':
main()
Error:
File "path", line 35, in
main()
File "path", line 32, in main
vk.method("messages.removeChatUser", {"chat_id": event.object.peer_id-2000000000, "user_id": event.user_id, "member_id": "user_id", "random_id": random.randint(1, 2147483647 )})
AttributeError: 'VkBotMessageEvent' object has no attribute 'user_id'
Answer the question
In order to leave comments, you need to log in
Do you want to kick yourself?
VkBotMessageEvent parameters:
from_user (bool) - message from user
from_chat (bool) - message from conversation
from_group (bool) - message from group
chat_id (int) - chat ID
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question