Home python Keyboard in Bot VK (Python, vk_api)

Keyboard in Bot VK (Python, vk_api)

Author

Date

Category

There has been a problem with connecting the keyboard in Python – Chat Bed VK:

Keyboard:

Keyboard = {
  "One_time": False,
  "Buttons": [
    [{
      "Action": {
        "TYPE": "Text",
        "PAYLOAD": "{\" button \ ": \" 1 \ "}"
         "Label": "Bot 123🤖"
      },
      "Color": "POSITIVE"
    }],
    [{
      "Action": {
        "TYPE": "Text",
        "PAYLOAD": "{\" button \ ": \" 2 \ "}"
        "Label": "Cinema 🎥"
      },
      "Color": "Default"
    },
    {
      "Action": {
        "TYPE": "Text",
        "PayLoad": "{\" button \ ": \" 3 \ "}",
        "Label": "Entertainment 🎉"
      },
      "Color": "Default"
      }
    ]
  ]
}
Keyboard = JSON.DUMPS (Keyboard, Ensure_Ascii = False) .Encode ('UTF-8')
Keyboard = STR (utf-8 '))

to display the message:

def new_message (Self, Message):
    # Hey
    If Message.upper () == Self._Commands [0]:
      Return F "Hi-Hi, {Self._userName}!"
    # Weather
    ELIF Message.upper () == Self._Commands [1]:
      Return Self._get_weather ()
    # Time
    ELIF Message.upper () == Self._Commands [2]:
      Return Self._Get_Time ()
    # Bye
    ELIF Message.upper () == Self._Commands [3]:
      Return F "So far, {Self._userName}!"
    ELSE:
      Return "I do not understand what you are about ..."

Trying to connect through “Keyboard”: keyboard, but after : writes that syntax error. Help please!


Answer 1

Most likely due to the fact that you have forgotten, or incorrectly put brackets.

Try this:

Keyboard = {
"One_time": False,
"Buttons": [
  [{
    "Action": {
      "TYPE": "Text",
      "PAYLOAD": "{\" button \ ": \" 1 \ "}"
      "Label": "Bot 123🤖"
    },
    "Color": "POSITIVE"
  }],
  [{
    "Action": {
      "TYPE": "Text",
      "PAYLOAD": "{\" button \ ": \" 2 \ "}"
      "Label": "Cinema 🎥"
    },
    "Color": "Default"
  }],
  [{
    "Action": {
      "TYPE": "Text",
      "PayLoad": "{\" button \ ": \" 3 \ "}",
      "Label": "Entertainment 🎉",
    },
    "Color": "Default"
  }],
 ]
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions