Answer the question
In order to leave comments, you need to log in
Why is the bot message not being deleted in the chat?
1. There is a bot on aiogram
2. There is an algorithm that deletes the just sent command by the user and the previous message sent by the bot to the user, which is a response to the previous user command.
2.1 The bot's message id is written to the user's database
2.2 The algorithm retrieves the id from the database and deletes the message using it
2.3 The algorithm itself:
async def del_last_bot_message(*args):
'''
Удаление лишних сообщений для реализации "чистого интерфейса"
'''
print(f'ENTER MESSAGE: {args[0].message_id + 1}')
# Удаление сообщения пользователя
try:
await args[0].delete()
except:
Exception
# Удаление последнего сообщения бота по id
bmi = dict(ast.literal_eval(database.select_user_data(args[0])))
while len(bmi['bot_mes_id']) > 0:
bmi = dict(ast.literal_eval(database.select_user_data(args[0])))
for ids in bmi['bot_mes_id']:
try:
print(f'TRY DEL MES: {ids} OF {args[0].from_user.username}')
await bot.delete_message(args[0].chat.id, ids)
print(f'DONE DEL MES: {ids} OF {args[0].from_user.username}')
database.del_bmi_element(args[0], ids)
print(f'DONE DEL ELEM: {ids} OF {args[0].from_user.username}')
except:
print(f'FAILE DEL MESSAGE: {ids} OF {args[0].from_user.username}')
continue
if len(bmi['bot_mes_id']) == 0:
database.create_bmi_in_user_data(args[0])
print(f'LAST FOO: {args[0].message_id + 1} {args[0].from_user.username}')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question