M
M
mikazyaka2020-04-17 00:08:23
Python
mikazyaka, 2020-04-17 00:08:23

How to return to the beginning of def?

I know, the question is mega-stupid, but on self-isolation, apparently, the brains have atrophied so much that I don’t understand anything anymore.
Until recently, I did not want to ask a question on such a stupid problem, but my nerves are already running out.
I write a bot in a cart in python

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 == 'На этом все':
            markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
            item10 = ('Да')
            item11 = ('Нет')
            markup.add(item10, item11)
            answer = ''
            for i in busket:
                answer += i
            bot.send_message(message.chat.id, 'Хорошо, получается ты заказал:' + answer + ' так?', reply_markup=markup)
    if message.chat.type == 'private':
        if message.text =='Да':
            bot.send_message(message.chat.id, 'Отлично, добавляю это в список заказов, жди когда примут.')


# RUN
bot.polling(none_stop=True)

It is necessary that when the final answer is 'No', the bot returns to the beginning of the def lalala function. At first I decided to just rewrite to
if message.text == 'Я хочу сделать заказ.':
if message.text == 'Я хочу сделать заказ.' or 'Нет':

But after such a cheeky move, the bot began to respond to every message 'OK, what do you want to order?'
I understand that this issue can be solved by a cycle, but each of my attempts ended with the fact that the bot started spamming the message 'OK, what do you want to order?'.
In impulses of loss of hope, I am writing here so that the sane minds of this divine site will tell you what to do.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Pokrovsky, 2020-04-17
@Makaroshka007

Make a cycle, only after sending "OK, what do you want to order?" put a break

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question