I am new to telegram bot development. I use python 3.9
My bot works fine when 1 person uses but 2 or more it gives me Error code: 400. Description: Bad Request: message to edit not found
I use pytelegrambotapi and imported telebot
Here is my code:
import telebot
@bot.message_handler(commands = ["start"])
def start_bot(message):
global user
#--------creating new user or load old user data--------
user = USER(message.chat.id)
#-----------asking-----------
if user.isFull():
user.last_message = bot.send_message(message.chat.id,
f"Hello {user.fish}",
reply_markup=MAIN_MENU)
else:
bot.delete_message(message.chat.id, message.message_id)
bot.send_message(message.chat.id, "*Some post", reply_markup=None)
user.info_post_id = bot.send_message(message.chat.id, user.user_info_checking()).message_id
user.last_message = bot.send_message(message.chat.id, 'Name:')
@bot.message_handler(content_types=['text'])
def get_name_and_age(message):
global user
chat_id = message.chat.id
if user.last_message.text=='Name:':
user.fish = message.text
bot.delete_message(chat_id, message.message_id)
bot.edit_message_text(chat_id=chat_id,
message_id=user.info_post_id,
text=user.user_info_checking(),
reply_markup=None)
user.last_message = bot.edit_message_text(chat_id=chat_id,
message_id=user.last_message.message_id,
text="Age:",
reply_markup=None)
I need to keep my bot chat clean so I need to delete or edit messages but I got the error. I used user class to save induvidual message and its id to track but still failed:
def __init__(self, id):
self.id = id
self.motion = None
self.info_post_id = None
self.last_message = None
self.last_error = None
self.post_counter = None
self.current_post = None
self.current_post_id = 0
self.current_post_link = None
self.current_catalog = None
self.current_channel_id = None
self.current_category = None
self.current_sub_category = None