Бот авто переходник для канала | End Way — сообщество разработчиков и готовых решений
  • Больше материалов без ожидания и лишних условий
    Доступ к скрытым публикациям на 2 месяца, 3 месяца или навсегда. Ограничения «Команда форума» и «Личный» сохраняются.

    Сравнить варианты доступа →

    🔔 EndWay в Telegram

    Следите за новостями и релизами:
    EndWay | EndSoft

Бот авто переходник для канала

iwasakura

Джун
Автор темы
25 Июн 2024
3
1
Бот автоматически меняет сообщение в телеграм канале и добавляет переходник канала.

Python:
import asyncio
import nest_asyncio
from telegram import Update
from telegram.ext import Application, MessageHandler, filters, CallbackContext
nest_asyncio.apply()
TOKEN = "" # Токен бота
CHANNEL_ID = -100 # ID канала
adapter_text = "<blockquote><b>Adapter: @</b></blockquote>" # Текст переходника
async def modify_message(update: Update, context: CallbackContext):
    if update.channel_post:
        if update.channel_post.chat.id == CHANNEL_ID and update.channel_post.text:
            original_message = update.channel_post.text
            modified_message = f"{original_message}\n\n{adapter_text}"
            try:
                await context.bot.edit_message_text(
                    chat_id=CHANNEL_ID,
                    message_id=update.channel_post.message_id,
                    text=modified_message,
                    parse_mode='HTML'
                )
            except Exception as e:
                print(f"Ошибка: {e}")
        elif update.channel_post.chat.id == CHANNEL_ID and update.channel_post.photo:
            photo_id = update.channel_post.photo[-1].file_id
            original_caption = update.channel_post.caption
            modified_caption = f"{original_caption}\n\n{adapter_text}"
            try:
                await context.bot.edit_message_caption(
                    chat_id=CHANNEL_ID,
                    message_id=update.channel_post.message_id,
                    caption=modified_caption,
                    parse_mode='HTML'
                )
            except Exception as e:
                print(f"Ошибка: {e}")
        elif update.channel_post.chat.id == CHANNEL_ID and update.channel_post.video:
            video_id = update.channel_post.video.file_id
            original_caption = update.channel_post.caption
            modified_caption = f"{original_caption}\n\n{adapter_text}"
            try:
                await context.bot.edit_message_caption(
                    chat_id=CHANNEL_ID,
                    message_id=update.channel_post.message_id,
                    caption=modified_caption,
                    parse_mode='HTML'
                )
            except Exception as e:
                print(f"Ошибка: {e}")
        elif update.channel_post.chat.id == CHANNEL_ID and update.channel_post.document:
            document_id = update.channel_post.document.file_id
            original_caption = update.channel_post.caption
            modified_caption = f"{original_caption}\n\n{adapter_text}"
            try:
                await context.bot.edit_message_caption(
                    chat_id=CHANNEL_ID,
                    message_id=update.channel_post.message_id,
                    caption=modified_caption,
                    parse_mode='HTML'
                )
            except Exception as e:
                print(f"Ошибка: {e}")
async def main():
    application = Application.builder().token(TOKEN).build()
    application.add_handler(MessageHandler(filters.ALL & filters.Chat(CHANNEL_ID), modify_message))
    await application.run_polling()
if __name__ == '__main__':
    asyncio.run(main())
 
  • 1
Реакции: 1 user
Активность:
Пока что здесь никого нет