J
J
judywb2020-09-15 12:20:30
Python
judywb, 2020-09-15 12:20:30

Why is there an error when creating a vkapi keyboard?

Why is there an error in this code when creating a keyboard:

import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
import random
import json


words_all = '1алаа, idueij, cuhdui, hifhu, hfhi'
words_all = words_all.split(',')
TOKEN = '800df4012535b065a9759a6b0abf1677aee086137a4ca8600bc7e019234a046959b56e9353ba753151cf2'

vk_session = vk_api.VkApi(token=TOKEN)
session_api = vk_session.get_api()

longpoll = VkLongPoll(vk_session)

def get_button(label, color, payload=''):
    return {
        'actions': {
            'type': 'text',
            'payload': json.dumps(payload),
            'label': label

        },
        'color': color
    }


keyboard = {
    'one_time': True,
    'buttons': {
        [get_button(label=random.choice(words_all), color='positive')]
    }
}
    
keyboard = json.dumps(keyboard, ensure_ascii=False).encode('utf-8')
keyboard = str(keyboard.decode('utf-8'))




for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW:
        if event.to_me:

            msg = event.text.lower()
            id = event.user_id

            vk_session.method('messages.send', {'peer_id': id, 'message': random.choice(words_all), 'keyboard': keyboard})
        
А именно в

keyboard = {
    'one_time': True,
    'buttons': {
        [get_button(label=random.choice(words_all), color='positive')]
    }
}


Namely here
keyboard = {
    'one_time': True,
    'buttons': {
        [get_button(label=random.choice(words_all), color='positive')]
    }
}

help me please

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question