Answer the question
In order to leave comments, you need to log in
Why don't buttons submit in a vertical list?
I create a keyboard object and send it to the user
def get_button(label, color, payload=""):
return {
"action": {
"type": "text",
"payload": json.dumps(payload),
"label": label
},
"color": color
}
keyboard = {
"one_time": False,
"buttons": [
[
get_button(label="Кнопка 1", color="positive"),
get_button(label="Кнопка 2", color="negative"),
get_button(label="Кнопка 3", color="primary"),
get_button(label="Кнопка 4", color="negative")
]
]
}
id = "id получателя"
vk.method("messages.send", {"peer_id": id, "message": "Открыто меню!", "keyboard": keyboard,
"random_id": random.randint(1, 2147483647)})
keyboard = {
"one_time": False,
"buttons": [
[
[get_button(label="Кнопка 1", color="positive")],
[get_button(label="Кнопка 2", color="negative")],
[get_button(label="Кнопка 3", color="primary")],
[get_button(label="Кнопка 4", color="negative")]
]
]
}
vk_api.exceptions.ApiError: [911] Keyboard format is invalid: button [0][3] has invalid action
Answer the question
In order to leave comments, you need to log in
No need to wrap the buttons in another array. Correct structure:
keyboard = {
'one_time': False,
'buttons': [
[get_button(label="Кнопка 1", color="positive")],
[get_button(label="Кнопка 2", color="negative")],
[get_button(label="Кнопка 3", color="primary")],
[get_button(label="Кнопка 4", color="negative")]
]
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question