A
A
animanshnik2019-04-07 19:25:21
Python
animanshnik, 2019-04-07 19:25:21

Problem with VK_API\LONGPOLL. How to make an input?

In general, the request is easy, but not for me. There is code for long polle.

from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import vk_api

vk = vk_api.VkApi(token="toktoken")

vk._auth_token()

vk.get_api()

longpoll = VkBotLongPoll(vk, id)

while True:
    for event in longpoll.listen():
        if event.type == VkBotEventType.MESSAGE_NEW:
            if event.object.peer_id != event.object.from_id:
                if event.object.text.lower() == "!kick ":
                    vk.method('messages.removeChatUser', {'chat_id': chat_id, 'user_id': member_id, 'member_id': member_id})

I need to make this vk.method by typing in vk. That is, !kick animanshnik , and this user was kicked, can you help?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Ternick, 2019-04-07
@animanshnik

Well, note 1:
What you have == is an equals sign, but for your task you need something else

from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import vk_api

vk = vk_api.VkApi(token="toktoken")

vk._auth_token()

vk.get_api()

longpoll = VkBotLongPoll(vk, id)

while True:
    for event in longpoll.listen():
        if event.type == VkBotEventType.MESSAGE_NEW:
            if event.object.peer_id != event.object.from_id:
                if "!kick " in event.object.text.lower(): #сюда надо бы добавить проверку кто это пишет, например если админ - выполнять или пропустить
                    user = event.object.text.lower().split(" ")[1] #И после этой строки получать всё необходимое для кика пользователя
                    vk.method('messages.removeChatUser', {'chat_id': chat_id, 'user_id': member_id, 'member_id': member_id})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question