D
D
Dmitry2020-06-30 13:45:57
Python
Dmitry, 2020-06-30 13:45:57

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'

5efb17d422e36481692934.jpeg5efb17e369342246507236.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-06-30
Kvili @Quile

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

D
Dmitri, 2020-06-30
@dmitriy337

Maybe user.id and not user_id ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question