S
S
shrhrthtrhrtshr2021-08-17 02:01:27
Python
shrhrthtrhrtshr, 2021-08-17 02:01:27

Error: AttributeError("'int' object has no attribute 'chat'"), who knows where he screwed up? I can't create a chain of consecutive functions.?

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)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-08-17
@shrhrthtrhrtshr

Register_next_step_handler is passed a message, not a chat_id.

bot.register_next_step_handler(call.message.chat.id, caclulate_usd)

change to
bot.register_next_step_handler(call.message, caclulate_usd)

And one more thing:
In the caclulate_usd function, you get an access to the call variable from somewhere , which is not defined inside this function, so there will also be a jamb there. Therefore, if you want to use call in this function, pass it through register_next_step_handler too
.......
                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)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question