P
P
python_nob2020-02-05 09:37:21
Python
python_nob, 2020-02-05 09:37:21

How to solve the problem with bot.polling()?

I made a test code for the bot according to the ready-made guide:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
import telebot
import config
import random

from telebot import types
from telebot import apihelper
#making proxy
apihelper.proxy = {'https':'socks5h://208.113.220.250:34571'}
#starting
bot=telebot.TeleBot(config.TOKEN)

@bot.message_handler(commands=['start'])
def welcome(message):
    message = 'привет!'
    # keyboard
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    item = 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 == 'Рандомное число':
            bot.send_message(message.chat.id, str(random.randint(0,100)))
        elif message.text == 'Как дела?':
            markup = types.InlineKeyboardMarkup(row_width=2)
            item1 = types.InlineKeyboardButton("Хорошо", callback_data='good')
            item2 = types.InlineKeyboardButton("Не очень", callback_data='bad')

            markup.add(item1, item2)

            bot.send_message(message.chat.id, 'Отлично, сам как?', reply_markup=markup)
        else:
            bot.send_message(message.chat.id, 'Я не знаю что ответить')

@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
    try:
        if call.message:
            if call.data == 'good':
                bot.send_message(call.message.chat.id, 'Вот и отличненько')
            elif call.data == 'bad':
                bot.send_message(call.message.chat.id, 'Бывает')

            # remove inline buttons
            bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Как дела?",
                reply_markup=None)

            # show alert
            bot.answer_callback_query(callback_query_id=call.id, show_alert=False,
                text="ЭТО ТЕСТОВОЕ УВЕДОМЛЕНИЕ!!11")

bot.polling(none_stop=True)

Everything seems to work, but an error appears:
5e3a6151d9d4a331813897.png

How can I fix it?

If there is a note to the code, I will also listen.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lev Slinsen, 2021-04-14
@Lev_Slinsen

The interpreter swears at indentation. Each indent must be exactly 4 spaces. The execution of python code depends on this.
https://www.w3schools.com/python/gloss_python_inde...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question