@shrhrthtrhrtshr

Ошибка: AttributeError("'int' object has no attribute 'chat'"), кто знает где налажал? Не могу создать цепочку последовательных функций.?

import telebot
import config
from telebot import types
import decimal

bot = telebot.TeleBot(config.TOKEN) 
@bot.message_handler(commands=['start'])
def welcome(message):
    sti = open('static/numbot.webp', 'rb')
    bot.send_sticker(message.chat.id, sti)

    bot.send_message(message.chat.id, "Hello, my commands are here below.\nIf you want more information, write  /info\n\n{0.first_name}, where do we begin? ".format(message.from_user, bot.get_me()),
		parse_mode='html')

@bot.message_handler(content_types=['text']) 
def inlinekeyboard(message):
    if message.chat.type == 'private':
    	if message.text == '⚖️Сalculate':

            markup = types.InlineKeyboardMarkup(row_width=3)
            item1 = types.InlineKeyboardButton("USD", callback_data='usd')
            item2 = types.InlineKeyboardButton("RUB", callback_data='rub')
            item3 = types.InlineKeyboardButton("UAH", callback_data='uah')

            markup.add(item1, item2, item3)
        
            bot.send_message(message.chat.id, 'Select the currency for the calculation ⤵️', reply_markup=markup)

@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
    try:
        if call.message:
            if call.data == 'usd':
                bot.send_message(call.message.chat.id, "$ Enter the amount of num ⤵️")
                bot.delete_message(call.message.chat.id, call.message.message_id)
                bot.register_next_step_handler(call.message.chat.id, caclulate_usd)

    except Exception as e:
        print(repr(e))

def caclulate_usd(message):
    num_usd = message.text
    bot.send_message(call.message.chat.id, 'Ваше запрос \"' + message.text +
                         '\" получен. Можете вернуться в главное меню ⤵', reply_markup=keyboard)

bot.polling(none_stop=True)
  • Вопрос задан
  • 2302 просмотра
Решения вопроса 1
@twistfire92
Python backend developer
В register_next_step_handler передается сообщение, а не chat_id.
bot.register_next_step_handler(call.message.chat.id, caclulate_usd)

меняйте на
bot.register_next_step_handler(call.message, caclulate_usd)


И еще:
В функции caclulate_usd у вас откуда-то берется обращение к переменной call, которая не определена внутри этой функции, так что там тоже будет косяк. Поэтому если хотите использовать call в этой функции, передавайте его тоже через register_next_step_handler
.......
                bot.register_next_step_handler(call.message, caclulate_usd, call)
.......

def caclulate_usd(message, call):
    num_usd = message.text
    bot.send_message(call.message.chat.id, 'Ваше запрос \"' + message.text +
                         '\" получен. Можете вернуться в главное меню ⤵', reply_markup=keyboard)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
SpectrumData Екатеринбург
от 150 000 до 200 000 ₽
Гринатом Москва
от 150 000 ₽
DIGITAL SECTOR Краснодар
от 150 000 до 250 000 ₽