A
A
alextimson2021-01-09 12:15:20
Python
alextimson, 2021-01-09 12:15:20

How to make sure that each bot button has its own response?

I took the code from the youtuber, but there was a problem. In his video, responses to commands are written in the same text, but with a capital letter.
How to make sure that each button has its own response?

The code:

import vk_api, json
from vk_api.longpoll import VkLongPoll, VkEventType
 
vk_session = vk_api.VkApi(token = "5252ea7755ab65ff5b6eabbd82aef29fd268144643132537ca24649aadd180ea947686b15cc50c1870820")
vk = vk_session.get_api()
longpol = VkLongPoll(vk_session)
 
def get_but(text, color):
    return {
                "action": {
                    "type": "text",
                    "payload": "{\"button\": \"" + "1" + "\"}",
                    "label": f"{text}"
                },
                "color": f"{color}"
            }
 
keyboard = {
    "one_time" : False,
    "buttons" : [
        [get_but('Скачать Killer The After You', 'primary')],
        [get_but('Получить бета-тест HookMan', 'positive')]
    ]
}
keyboard = json.dumps(keyboard, ensure_ascii = False).encode('utf-8')
keyboard = str(keyboard.decode('utf-8'))
 
def sender(id, text):
    vk_session.method('messages.send', {'user_id' : id, 'message': text, 'random_id' : 0, 'keyboard' : keyboard})
 
def main():
    for event in longpol.listen():
        if event.type == VkEventType.MESSAGE_NEW:
            if event.to_me:
 
                id = event.user_id
                msg = event.text.lower()
 
                sender(id, msg.upper())
 
while True:
    main()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mixxe73, 2021-01-09
@mixxe73

Check the pressed button and then perform the action you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question