@apiwi

Как сделать несколько клавиатур в vk_api?

Имеется бот с клавиатурой, как сделать, чтоб после нажатия кнопки на клавиатуре, появлялась уже новая клавиатура?

def write_msg(self, user_id, message):
		try:
			self.vk.method('messages.send', {'user_id': user_id, 'message': message, 'keyboard': keyboard, 'random_id': random.randint(0, 100000000)})
		except Exception as ex:
			print("error (write_msg, {0}, {1}):".format(user_id, message), ex)


Вот первая клава:
keyboard = '''
{
   "one_time": false,
   "buttons": [
      [
         {
            "action": {
               "type": "text",
               "label": "Подписаться"
            },
            "color": "positive"
         },
         {
            "action": {
               "type":"text",
               "label":"Отписаться"
            },
            "color": "negative"
         },
		 {
            "action": {
               "type":"text",
               "label":"Команды"
            },
            "color": "primary"
		}
		 
      ]
   ]
}
'''


Вот вторая, которую нужно добавить:
keyboard2 = '''
{
   "one_time": false,
   "buttons": [
      [
         {
            "action": {
               "type": "text",
               "label": "Кнопка 1"
            },
            "color": "positive"
         },
         {
            "action": {
               "type":"text",
               "label":"Кнопка 2"
            },
            "color": "negative"
         },
		 {
            "action": {
               "type":"text",
               "label":"Вернуться назад"
            },
            "color": "primary"
		}
		 
      ]
   ]
}
'''


Хотелось, чтоб было бы вот так:
for event in self.longpoll.listen():
					if event.type == VkEventType.MESSAGE_NEW and event.to_me:
						id = event.user_id
						msg = event.text.lower()
						if msg == "подписаться":
							#ТОГДА ПОКАЖИ ЮСЕРУ КЛАВИАТУРУ НОМЕР 2!!!
  • Вопрос задан
  • 354 просмотра
Решения вопроса 1
@megared
def write_msg(self, user_id, message, key):
    try:
      self.vk.method('messages.send', {'user_id': user_id, 'message': message, 'keyboard': key, 'random_id': random.randint(0, 100000000)})
    except Exception as ex:
      print("error (write_msg, {0}, {1}):".format(user_id, message), ex)
for event in self.longpoll.listen():
          if event.type == VkEventType.MESSAGE_NEW and event.to_me:
            id = event.user_id
            msg = event.text.lower()
            if msg == "подписаться":
                write_msg(id, 'Подписались', keyboard2)

В write_msg вместо key пишешь название клавиатуры.
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
mlneko
@mlneko
keyboard = '''
{
   "one_time": false,
   "buttons": [
      [
         {
            "action": {
               "type": "text",
               "label": "Подписаться"
            },
            "color": "positive"
         },
         {
            "action": {
               "type":"text",
               "label":"Отписаться"
            },
            "color": "negative"
         },
     {
            "action": {
               "type":"text",
               "label":"Команды"
            },
            "color": "primary"
    }
     
      ]
[
         {
            "action": {
               "type": "text",
               "label": "Кнопка 1"
            },
            "color": "positive"
         },
         {
            "action": {
               "type":"text",
               "label":"Кнопка 2"
            },
            "color": "negative"
         },
     {
            "action": {
               "type":"text",
               "label":"Вернуться назад"
            },
            "color": "primary"
    }
     
      ]
   ]
}
'''

Может вот так?
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы