0

Буду короток. Есть бот напсанный на Python 3 с библиотекой telebot.

Нужно, что бы при вводе команды /cls все, что было выше этой команды стерлось.
Как это реализовать?

Исходный код:

import telebot


token = '...'
bot = telebot.TeleBot(token)

@bot.message_handler(commands= ['start', 'help'])
def answer_commands(message):
    bot.send_message(message.chat.id, 'clear')
    photo= open('fytch.jpg', 'rb')
    bot.send_photo(message.chat.id, photo)
    bot.send_message(message.chat.id, 'You call me\nMy goal all show you\nLook')

@bot.message_handler(commands= [cls])
def cls():
passs

bot.infinity_polling()

1 ответ 1

1

Вы можете удалить сообщение через telebot методом delete_message, зная его chat_id и message_id. При этом соблюдая правила, приведенные в цитате ниже.

У бота нет доступа к истории сообщений. Поэтому для удаления сообщений потребуется сохранять message_id на своей стороне.

  • A message can only be deleted if it was sent less than 48 hours ago.
  • A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.
  • Bots can delete outgoing messages in private chats, groups, and supergroups.
  • Bots can delete incoming messages in private chats.
  • Bots granted can_post_messages permissions can delete outgoing messages in channels.
  • If the bot is an administrator of a group, it can delete any message there.
  • If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
1
  • you can help to correctly compose this part?
    – Nappy Says
    7 июн 2020 в 14:06

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.