I'm building a telegram bot which sends three dices with bot.send_dice()
. In the code I collect their IDs into a list and then I'm creating new loop to delete every message. start_message
is a message id which was sent earlier
messages = []
time.sleep(0.1)
bot.delete_message(chat_id=callback.message.chat.id,
message_id=start_message.id,)
time.sleep(0.1)
for _ in range(3):
dice_message = bot.send_dice(callback.message.chat.id,
emoji="🎲")
messages.append(dice_message.id)
time.sleep(6)
for d in range(3):
bot.delete_message(chat_id=callback.message.chat.id,
message_id=messages[d])
This code is inside this function:
@bot.callback_query_handler(func=lambda call:True)
def main(callback):
'my code'
I'm getting an error:
telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: message can't be deleted for everyone
I was expecting that the code would delete all messages in the messages
list. But it didn't. I tried deleting time.sleep(time)
lines from my code, but it didn't work.
According to the documentation:
A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.