import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from vk_api.utils import get_random_id
vk_session = vk_api.VkApi(token="tokengroup")
longpoll = VkBotLongPoll(vk_session, 'idgroup')
vk = vk_session.get_api()
while True:
try:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW and event.raw['object']['message']['action']['type'] == 'chat_invite_user' and event.raw['object']['message']['action']['member_id'] == -12345678: #вместо -12345678 впишите id своей группы
vk.messages.send(
peer_id=event.message.peer_id,
random_id=get_random_id(),
message="Тест"
)
except Exception as e:
print(e)
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from vk_api.utils import get_random_id
import random
vk_session = vk_api.VkApi(
token='TOKENGROUP')
longpoll = VkBotLongPoll(vk_session, 'IDGROUP')
vk = vk_session.get_api()
while True:
try:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
response = str(event.message.text)
text = str(event.message.text.lower())
peer_id = str(event.message.peer_id)
from_id = str(event.message.from_id)
message = text.split(' ', 10)
if message[0] == '/инфа':
texts = response[5:]
infa = random.randint(1, 100)
vk.messages.send(
peer_id=peer_id,
random_id=get_random_id(),
message=f'Вероятность, что {texts} {infa}%'
)
except Exception as e:
print(e)