M
M
Mikhail Evseev2022-01-12 10:25:16
Python
Mikhail Evseev, 2022-01-12 10:25:16

Why does the bot send the result of the action to me and not to the user?

Good afternoon, the problem is that when I use the bot, everything works correctly, but when others try to use it, it answers all commands, but for some reason sends the result of the calculation to me, what's the matter?

@bot.message_handler(commands=['spam'])
def start_message(message):
    bot.send_message(message.chat.id, 'Пиши что угодно')
    @bot.message_handler(content_types=['text'])
    def get_text(message):
        text = message.text
        markup = telebot.types.InlineKeyboardMarkup()
        markup.add(telebot.types.InlineKeyboardButton(text='Десять', callback_data=10))
        markup.add(telebot.types.InlineKeyboardButton(text='Пятьдесят', callback_data=50))
        markup.add(telebot.types.InlineKeyboardButton(text='Сто', callback_data=100))
        bot.send_message(message.chat.id, text="Выбери сколько раз повторить", reply_markup=markup)

        @bot.callback_query_handler(func=lambda call: True)
        def query_handler(call):
            bot.answer_callback_query(callback_query_id=call.id, text='11111')
            so = []
            bot.send_message(message.chat.id, f'Пишем {call.data} раз')
            for i in range(int(call.data)):
                so.append(text)
                sos = '\n'.join(so)
            bot.send_message(message.chat.id, sos)

I understand that the question is easy and the mistake is probably that I didn’t specify the sending path somewhere, but I don’t see it at point blank range (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2022-01-12
@ultraevs

Why did you make a nested function structure? They should all be top notch.

@bot.message_handler(commands=['spam'])
def start_message(message):
    bot.send_message(message.chat.id, 'Пиши что угодно')

@bot.message_handler(content_types=['text'])
def get_text(message):
    text = message.text
    markup = telebot.types.InlineKeyboardMarkup()
    markup.add(telebot.types.InlineKeyboardButton(text='Десять', callback_data=10))
    markup.add(telebot.types.InlineKeyboardButton(text='Пятьдесят', callback_data=50))
    markup.add(telebot.types.InlineKeyboardButton(text='Сто', callback_data=100))
    bot.send_message(message.chat.id, text="Выбери сколько раз повторить", reply_markup=markup)

@bot.callback_query_handler(func=lambda call: True)
def query_handler(call):
    bot.answer_callback_query(callback_query_id=call.id, text='11111')
    so = []
    bot.send_message(message.chat.id, f'Пишем {call.data} раз')
    for i in range(int(call.data)):
        so.append(text)
        sos = '\n'.join(so)
    bot.send_message(call.message.chat.id, sos)

And yes, in the last line you cannot access the message object directly, only through call

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question