Answer the question
In order to leave comments, you need to log in
Why does the function with vk api buttons not work?
Hello!
Faced such a problem: when I replace the button code with the main_menu () function, an error appears.
Error:
Traceback (most recent call last):
File "C:\Users\Alex\Desktop\mybot\problem.py", line 41, in
write(sender, "Hi")
File "C:\Users\Alex\Desktop \mybot\problem.py", line 10, in write
vk.method("messages.send",{'user_id': sender,'message': message,"random_id": get_random_id(), 'keyboard': keyboard. get_keyboard()})
File "C:\Users\aleksey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\vk_api\vk_api.py", line 656, in method
raise error
vk_api.exceptions.ApiError: [911] Keyboard format is invalid: row 0 contains too many columns
This part of the code is:
keyboard = VkKeyboard(one_time=True)
def write(sender, message): #функция для ответа в диалоге
vk.method("messages.send",{'user_id': sender,'message': message,"random_id": get_random_id(), 'keyboard': keyboard.get_keyboard()})
def main_menu():
keyboard = VkKeyboard(one_time=True)
keyboard.add_button('Баланс', color=VkKeyboardColor.SECONDARY)
keyboard.add_button('Услуги', color=VkKeyboardColor.SECONDARY)
keyboard.add_line()
keyboard.add_button('Тарифы', color=VkKeyboardColor.SECONDARY)
keyboard.add_button('Роуминг', color=VkKeyboardColor.SECONDARY)
keyboard.add_line()
keyboard.add_button('Вызвать оператора', color=VkKeyboardColor.PRIMARY)
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
text = event.text
sender = event.user_id
if b==0:
main_menu()
#keyboard = VkKeyboard(one_time=True)
#keyboard.add_button('Баланс', color=VkKeyboardColor.SECONDARY)
#keyboard.add_button('Услуги', color=VkKeyboardColor.SECONDARY)
#keyboard.add_line()
#keyboard.add_button('Тарифы', color=VkKeyboardColor.SECONDARY)
#keyboard.add_button('Роуминг', color=VkKeyboardColor.SECONDARY)
#keyboard.add_line()
#keyboard.add_button('Вызвать оператора', color=VkKeyboardColor.PRIMARY)
write(sender, "Привет")
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question