R
R
Roman Roman2020-05-13 00:34:15
Python
Roman Roman, 2020-05-13 00:34:15

Code not working?

import os
import datetime
import telebot
from telebot import types


bot = telebot.TeleBot('1087018832:AAEUODlCX-NUC8LOumeedO1')
menu = ["Піца", "Чай","Кава","Морозиво","Суші", "margherita", "havaiska"]
how =  ["1", "2","3","4","5", "6", "7"]

class TestTeleBot:
    def __init__(self):

        self.bot_polling()

    @bot.message_handler(commands=['menu'])
    def start_message(message):
        print('-------------------------------------------------------------------')
        print(datetime.datetime.fromtimestamp(message.date).strftime('%H:%M:%S %d-%m-%Y'))
        print(message.text)
        print(message.from_user.id)
        print(message.from_user.first_name)
        print(message.from_user.last_name)
        print(message.from_user.username)
        print('-------------------------------------------------------------------')
        keyboard_menu = types.InlineKeyboardMarkup()
        pizza = types.InlineKeyboardButton(text="Піцца", callback_data="pizza")
        tea = types.InlineKeyboardButton(text="Чай", callback_data="tea")
        keyboard_menu.add(pizza, tea)
        bot.send_message(message.chat.id, 'Вибери теі що тобі інтересно', reply_markup=keyboard_menu)
    @bot.callback_query_handler(func=lambda call:True)
    def handler_item_menu(callback):
        print("Отримав")
        if callback.data == "pizza":
            keyboard_name = types.InlineKeyboardMarkup()
            margherita = types.InlineKeyboardButton(text="Маргарита", callback_data="margherita")
            havaiska = types.InlineKeyboardButton(text="Гавайська", callback_data="havaiska")
            keyboard_name.add(margherita, havaiska)
            bot.edit_message_text(chat_id=callback.message.chat.id, message_id=callback.message.message_id, text="Вибери те що тобі інтересно", reply_markup=None)
            bot.send_message(callback.from_user.id, 'Яка?', reply_markup=keyboard_name)
        elif callback.data == "margherita":
            if callback.data in menu:
                how_m = types.ReplyKeyboardMarkup(resize_keyboard=True)
                how_m.add(*[types.KeyboardButton(name) for name in how])
                bot.send_message(callback.from_user.id, "Яка кількість?", reply_markup=how_m)
            else:
                bot.send_message(callback.from_user.id, "Немає такого товару  наявонсті")
        elif callback.data == "havaiska":
            if callback.data in menu:
                how_m = types.ReplyKeyboardMarkup(resize_keyboard=True)
                how_m.add(*[types.KeyboardButton(name) for name in how])
                bot.send_message(callback.from_user.id, "Яка кількість?", reply_markup=how_m)
            else:
                bot.send_message(callback.from_user.id, "Немає такого товару  наявонсті")
        if callback.data == "tea":
            pass
    @bot.callback_query_handler(func=lambda call:True)
    def handler_item_how(call):
        if call.data == "1":
            Yes = types.InlineKeyboardButton(text="Так", callback_data="Yes")
            No = types.InlineKeyboardButton(text="Ні", callback_data="No")
            t_f.add(Yes, No)
            bot.send_message(call.from_user.id, "Це все?", reply_markup=t_f)
    def bot_polling(self):
        return bot.polling(none_stop=True)

def main():
    testTeleBot = TestTeleBot()
if __name__ == '__main__':
    main()

How to fix the code so that it is written to a variable quantity of goods that the customer specifies

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