S
S
Snowdevil2021-06-24 16:08:00
Python
Snowdevil, 2021-06-24 16:08:00

How to kick a user from a conversation with a bot?

I made this kick, in response to a message, but it gives an error: vk.method("messages.removeChatUser", {"chat_id": event.object.peer_id - 2000000000, "member_id": event.obj.reply_message['from_id' ]})
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

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


vk_session = VkApi(token='1adbd73f02bcfa805970387d5df1a176dc37fdb07eff4b7c97af0edd3be7b409643e9c706c5f')
vk = vk_session.get_api()

longpoll = VkBotLongPoll(vk_session, '205284886')
for event in longpoll.listen():
    if event.type == VkBotEventType.MESSAGE_NEW:
        message = event.obj['message']

        peer_id = message['peer_id']
        text = message['text']

        if text.lower() == 'привет':
            vk.messages.send(peer_id = peer_id, message = '123', random_id = get_random_id())

        if text.lower() == "кик":
            vk.method("messages.removeChatUser", {"chat_id": event.object.peer_id - 2000000000, "member_id": event.obj.reply_message['from_id']})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeniy _, 2021-06-24
@GeneD88

event.obj.peer_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question