W
W
WolfInChains2020-05-07 21:25:23
Python
WolfInChains, 2020-05-07 21:25:23

How to make the bot respond to a command if there is other text after it?

There is such a piece. How to make the bot respond to a message when there are other words after "infa", but at the same time so that it reacts to the message only if "infa" is the first word in the message.

if event.object.text == "Инфа" or event.object.text == "инфа":
                       percent = random.randint(0, 100)
                       vk.method("messages.send",
                                 {
                                     "chat_id": event.object.peer_id - 2000000000,
                                     "message": "Вероятность этого " + f'{percent}' + "%",
                                     "random_id": random.randint(1, 2147483647)
                                 })

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Ivanov, 2020-05-07
@WolfInChains

It's simple, split the string via split(' '), then check that split[0] == 'infa', then a series of checks for the second word after 'infa' (if(split[1] = 'some'))
Example:

str = "инфа 123"
arr = str.split(" ")
#arr[0] - инфа
#arr[1] - первое слово после слово инфа, после пробела.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question