'Telegram bot Error - AttributeError: 'int' object has no attribute 'chat'

What does this error mean and what do I need to do to make my code work?

This bot is a random number generator with customizable number range. It gets the first digit of the range, then the second digit of the range, and after that it inserts these numbers into the random range.

import telebot
import random
from telebot import types

bot = telebot.TeleBot('TOKEN')


# Start
@bot.message_handler(commands=['start'])
def welcome(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    random_sender = types.KeyboardButton("Send me Random Number")
    markup.add(random_sender)
    bot.send_message(message.chat.id, '<b>Random Generator activated</b>', parse_mode='html',
                     reply_markup=markup)


# Button
@bot.message_handler(content_types=['text'])

# Getting the first number of range
def first_number_ask(message):
    if message.text == 'Send me Random Number':
        msg = bot.send_message(message.chat.id, 'Enter the first number of range')
        bot.register_next_step_handler(msg, second_number_get)

def first_number_get(message):
    global NUM_first
    NUM_first = int(message.text)
    bot.register_next_step_handler(NUM_first, second_number_ask)


# Getting the second number of range
def second_number_ask(message):
    msg = bot.send_message(message.chat.id, 'Enter the second number of range')
    bot.register_next_step_handler(msg, second_number_get)

def second_number_get(message):
    global NUM_second
    NUM_second = int(message.text)
    bot.register_next_step_handler(NUM_second, result)


# Result
def result(message):
    bot.send_message(message.chat.id, str(random.randint(NUM_first, NUM_second)))

#Run
bot.polling(none_stop=True)


Solution 1:[1]

It should work. Also you can check this example

import telebot
import random
from telebot import types

bot = telebot.TeleBot('TOKEN')


# Start
@bot.message_handler(commands=['start'])
def welcome(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    random_sender = types.KeyboardButton("Send me Random Number")
    markup.add(random_sender)
    bot.send_message(message.chat.id, '<b>Random Generator activated</b>', parse_mode='html',
                     reply_markup=markup)


# Button
@bot.message_handler(content_types=['text'])

def first_number_step(message):
    if message.text == 'Send me Random Number':
        msg = bot.send_message(message.chat.id, 'Enter the first number of range')
        bot.register_next_step_handler(msg, second_number_step)

def second_number_step(message):
    global NUM_first
    NUM_first = int(message.text)
    msg = bot.send_message(message.chat.id, 'Enter the second number of range')
    bot.register_next_step_handler(msg, result_number_step)


def result_number_step(message):
    global NUM_second
    NUM_second = int(message.text)
    result(message)
    
# Result
def result(message):
    bot.send_message(message.chat.id, 'Random number: ' + str(random.randint(NUM_first, NUM_second)))

#Run
bot.polling(none_stop=True)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1