0
0
0x00000072021-08-10 18:34:31
Python
0x0000007, 2021-08-10 18:34:31

How to get message after command?

I'm learning python, I wanted to make a page calculator in VK.
I ran into a problem, I don't know how to get an example after '.solve'

import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
import random

def mathvk():
    vk_session = vk_api.VkApi(
        token="token")

    try:
        vk = vk_session.get_api()
    except vk_api.AuthError as error_msg:
        print(error_msg)
        return

    longpoll = VkLongPoll(vk_session)

    for event in longpoll.listen():
        if event.type == VkEventType.MESSAGE_NEW and event.from_user:
            peer = str(int(event.user_id))
            print(event.text)
            if '.реши' in event.text:
                try:
                    vk.messages.send(peer_id=peer, message='ответ на пример здесь.' random_id=str(random.randint(1, 99999)), v=5.124)
                except:
                    vk.account.setOffline()

if __name__ == '__main__':
    mathvk()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LXSTVAYNE, 2021-08-11
@0x0000007

It is possible like this:

text = '.реши 1 + 1'
    if text.startswith('.реши'):
        print(text[5:])

If you want to write a community bot, you can try this library: https://github.com/lxstvayne/vk_maria

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question