xiao9469 发表于 2024-7-7 20:54:37

mjj们 有没有办法实现tg监听群组实时转发?

有个群组发的媒体文件 60秒自动撤回
有没有办法就是监听这个群组 有媒体文件就自动转发到另一个群组?

浅生 发表于 2024-7-7 20:55:12

楼下来回答吧

TyCoding 发表于 2024-7-7 20:56:09

很简单

IT618发布 发表于 2024-7-7 20:56:50

群组地址多少,私我我看看

独家记忆 发表于 2024-7-7 20:57:46

from telegram import Update, Bot
from telegram.ext import Updater, MessageHandler, Filters, CallbackContext

# 替换为您的 Bot Token
BOT_TOKEN = 'YOUR_BOT_TOKEN'
# 源群组的 Chat ID
SOURCE_CHAT_ID = -1001234567890
# 目标群组的 Chat ID
TARGET_CHAT_ID = -1009876543210

def media_forwarder(update: Update, context: CallbackContext):
    message = update.message
   
    # 检查消息是否来自指定的源群组
    if message.chat_id == SOURCE_CHAT_ID:
      # 检查消息中是否有媒体文件
      if message.photo:
            context.bot.send_photo(chat_id=TARGET_CHAT_ID, photo=message.photo[-1].file_id, caption=message.caption)
      elif message.video:
            context.bot.send_video(chat_id=TARGET_CHAT_ID, video=message.video.file_id, caption=message.caption)
      elif message.document:
            context.bot.send_document(chat_id=TARGET_CHAT_ID, document=message.document.file_id, caption=message.caption)
      elif message.audio:
            context.bot.send_audio(chat_id=TARGET_CHAT_ID, audio=message.audio.file_id, caption=message.caption)
      elif message.voice:
            context.bot.send_voice(chat_id=TARGET_CHAT_ID, voice=message.voice.file_id, caption=message.caption)
      elif message.animation:
            context.bot.send_animation(chat_id=TARGET_CHAT_ID, animation=message.animation.file_id, caption=message.caption)

def main():
    updater = Updater(token=BOT_TOKEN, use_context=True)
    dispatcher = updater.dispatcher

    # 添加处理媒体文件消息的处理器
    media_handler = MessageHandler(Filters.chat(chat_id=SOURCE_CHAT_ID) & Filters.media, media_forwarder)
    dispatcher.add_handler(media_handler)

    # 启动机器人
    updater.start_polling()
    updater.idle()

if __name__ == '__main__':
    main()

Crystαl 发表于 2024-7-7 20:57:51

这个代码是需要把机器人加进源群组么

TyCoding 发表于 2024-7-7 20:58:49

用协议号监听

TyCoding 发表于 2024-7-7 20:59:11

hous135 发表于 2024-7-7 17:42
用协议号监听
协议号有 监听怎么实现呢

IT618发布 发表于 2024-7-7 20:59:23

建议先去了解一下telegram api hash
页: [1]
查看完整版本: mjj们 有没有办法实现tg监听群组实时转发?

创宇盾启航版免费网站防御网站加速服务