M
M
mikazyaka2020-04-13 21:44:06
Python
mikazyaka, 2020-04-13 21:44:06

Telebot doesn't work with list. Python?

I am writing a Python bot for a cart using Telebot.
It is required to prompt the user for the elements of the list and eventually give it back.
Faced with the fact that no matter how the list (busket) was filled, the bot still gives out only the first element of the list.
How to force to issue it all list?

import telebot
import config

from telebot import types

bot = telebot.TeleBot(config.TOKEN)

@bot.message_handler(commands=['start'])
def welcome(message):
    sti = open('sticker.webp', 'rb')
    bot.send_sticker(message.chat.id, sti)

    # keyboard
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    item1 = types.KeyboardButton("Я хочу сделать заказ.")
    item2 = types.KeyboardButton("Я хочу принять заказ.")

    markup.add(item1, item2)

    bot.send_message(message.chat.id, "Добро пожаловать, {0.first_name}!\nЯ - <b>{1.first_name}</b>, бот заказчик, ты можешь заказать у меня еду в столовке, после чего твой заказ увидит любой человек из очереди и купит тебе еду.".format(message.from_user, bot.get_me()),
        parse_mode='html', reply_markup=markup)




@bot.message_handler(content_types=['text'])
def lalala(message):
    if message.chat.type == 'private':
        if message.text == 'Я хочу сделать заказ.':
            global busket
            busket = []
            markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
            item3 = ('Пицца')
            item4 = ('Чай')
            item5 = ('Круассан')
            item6 = ('Колобок')
            item7 = ('Сырная')
            item8 = ('Сосиска в тесте')
            item9 = ('На этом все')
            markup.add(item3, item4, item5, item6, item7, item8, item9)
            bot.send_message(message.chat.id, 'Хорошо, что ты хочешь заказать?', reply_markup=markup)
        if message.chat.type == 'private':
            if message.text == 'Пицца':
                busket.append('Пицца')
            elif message.text == 'Чай':
                busket.append('Чай')
            elif message.text == 'Круассан':
                busket.append('Круассан')
            elif message.text == 'Колобок':
                busket.append('Колобок')
            elif message.text == 'Сырная':
                busket.append('Сырная')
            elif message.text == 'Сосиска в тесте':
                busket.append('Сосиска в тесте')
            elif message.text == 'На этом все':
                bot.send_message(message.chat.id, busket)


# RUN
bot.polling(none_stop=True)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Pokrovsky, 2020-04-13
@mikazyaka

Maybe so?

answer = ''
for i in busket:
    answer += i
send_message(message.chat.id, answer)

Instead of
bot.send_message(message.chat.id, busket)

A
Alexander, 2020-04-13
@shabelski89

The bot only outputs strings, but how can you think with your head?)
If it's a list, then you can go through the elements?)

for elem in list_b:
    bot.send_message(userid, elem)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question