Телеграм бот. Ошибка. ImportError: cannot import name 'AdminLogEventAction' from 'telegram.constants'
Не могу понять, почему ошибка при создании бота тг, помогите пожалуйста. Библиотека 20 версии.
ImportError: cannot import name 'AdminLogEventAction' from 'telegram.constants'
from telegram import Update
from telegram.ext import Updater, CommandHandler, CallbackContext
from telegram.constants import AdminLogEventAction
import datetime
TOKEN = ""
async def restore(update: Update, context: CallbackContext):
chat_id = update.effective_chat.id
user = update.effective_user
# Проверка на администратора
admins = await context.bot.get_chat_administrators(chat_id)
if user.id not in [admin.user.id for admin in admins]:
await update.message.reply_text("❌ Только администраторы могут использовать эту команду")
return
# Поиск удаленных сообщений за 48 часов
time_threshold = datetime.datetime.now() - datetime.timedelta(hours=48)
try:
admin_logs = await context.bot.get_admin_log(
chat_id=chat_id,
limit=100,
events_filter=AdminLogEventAction.DELETE_MESSAGES,
min_date=time_threshold
)
restored_count = 0
# Восстановление сообщений
for event in admin_logs:
if event.action == AdminLogEventAction.DELETE_MESSAGES:
for msg in event.deleted_messages:
try:
if msg.text:
await context.bot.send_message(
chat_id=chat_id,
text=f"💬 Сообщение от @{msg.sender_user.username or msg.sender_user.first_name} "
f"({msg.date.strftime('%d.%m.%Y %H:%M')}):\n{msg.text}"
)
restored_count += 1
if msg.photo:
await context.bot.send_photo(
chat_id=chat_id,
photo=msg.photo[-1].file_id,
caption=msg.caption
)
restored_count += 1
except Exception as e:
print(f"Ошибка: {e}")
await update.message.reply_text(f"♻️ Восстановлено сообщений: {restored_count}")
except Exception as e:
await update.message.reply_text("❌ Ошибка! Проверьте права бота")
def main():
updater = Updater(TOKEN)
dp = updater.dispatcher
dp.add_handler(CommandHandler("restore", restore))
updater.start_polling()
updater.idle()
if __name__ == "__main__":
main()
Может потому что в telegram.constants нет никаких AdminLogEventAction?