import vk_api
from vk_api import VkApi
import random, vk_api.bot_longpoll
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import time
vk_session = vk_api.VkApi(token = "tokenhere" )
longpoll = VkBotLongPoll (vk_session, groupid)
vk = vk_session.get_api()
global Random
def random_id():
Random = 0
Random += random.randint(0, 90000000000)
return Random
while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW and event.to_me and event.text:
if event.text.lower() == "ping":
vk.messages.send(
user_id = event.user_id,
message = "pong",
random_id = random_id()
)
elif event.text.lower () == "kbd":
vk.messages.send(
user_id = event.user_id,
message = "Added",
keyboard = open("jsonvk.json", "r", encoding="utf-8"). read(),
random_id = random_id()
)
elif event.text.lower () == "kbdr":
vk.messages.send(
user_id = event.user_id,
message = "Removed",
keyboard = open("jsovkr.json", "r", encoding="utf-8"). read(),
random_id = random_id()
)
elif event.from_chat:
if event.text == "1":
vk.messages.send(
chat_id = event.chat_id,
messages = "here",
random_id = random_id()
)
import vk_api, random, time
from vk_api.longpoll import VkLongPoll, VkEventType
vk = vk_api.VkApi(token='token')
longpoll = VkLongPoll(vk)
def send(message):
if event.from_user: # Для ЛС
vk.method('messages.send', {'user_id': event.user_id, 'message': message, 'random_id': random.getrandbits(64)})
elif event.from_chat: # Для бесед
vk.method('messages.send', {'chat_id': event.chat_id, 'message': message, 'random_id': random.getrandbits(64)})
while True:
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
text = event.text.lower()
u_id = event.user_id # (Если будет нужно)
if text == 'ping': # Пример
send('pong')