Answer the question
In order to leave comments, you need to log in
How to teach a bot to kick users from a conversation?
Good afternoon, I can't teach a bot to kick a user from a conversation.
I will be grateful for your help!
Example:
kick @id
import random
import json
from vk_api import VkApi
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import time
from vk_api.utils import get_random_id
ping = 'пау!','понг!','понг','пау'
print("")
print("====================================")
print("")
print("Бот работает!")
print("")
print("====================================")
time.sleep(0.2)
def counter(user):
file = open("stats.json", "r") # "r" - read , "w" - write
data = json.loads(file.read())
data["counter"] += 1
if user not in data["users"]:
data["users"].append(user)
file = open("stats.json", "w")
file.write(json.dumps(data))
def getCounter():
file = open("stats.json", "r") # "r" - read , "w" - write
data = json.loads(file.read())
return data["counter"]
def getUsers():
file = open("stats.json", "r") # "r" - read , "w" - write
data = json.loads(file.read())
return len(data["users"])
def main() -> None:
vk_session = VkApi(token=цензура')
long_poll = VkBotLongPoll(vk_session, 'хых')
vk = vk_session.get_api()
users = vk.users
for event in long_poll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
time.sleep(0.2)
peer_id = event.obj['peer_id']
message = event.obj['text'].lower()
counter(peer_id)
if message == 'ку':
vk.messages.send(
peer_id=peer_id,
message='Бонжур!',
random_id=get_random_id(),
)
if message == "пинг" or message == "ping":
vk.messages.send(peer_id=peer_id, random_id=get_random_id(), message=ping[random.randint(0, len(ping) - 1)],)
if message == 'сколько сообщений обработано' or message == 'ссо':
vk.messages.send(
peer_id=peer_id,
message="Cообщений обработано: " + str(getCounter()) + "\n"
"\n"
"Цель: 10000 сообщений \n"
"Собрано: " + str(getCounter()) +"/10000 сообщений",
random_id=get_random_id(),
)
if __name__ == '__main__':
main()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question