Python
1
Вклад в тег
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)