V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
shinonome
V2EX  ›  Python

telethon 有什么方法可以给一个事件添加两个监听吗

  •  
  •   shinonome · 2022-09-21 20:00:56 +08:00 · 1412 次点击
    这是一个创建于 576 天前的主题,其中的信息可能已经有所发展或是发生改变。
    client = TelegramClient('telegramfw', api_id, api_hash)
    
    @client.on(events.NewMessage)
    @client.on(events.MessageEdited)
    async def handler(event):
        chat = await event.get_chat()
    
        chat_id = event.chat_id
        print(chat_id)
        if chat_id == -1001629488043:
            if event.photo:
                await client.send_file(-1001567215170, event.photo,  caption=event.raw_text)
            elif event.video:
                await client.send_file(-1001567215170, event.video, caption=event.raw_text)
            else:
                msg = event.raw_text
                print(msg)
                msg_id_source = event.message.id
                await client.send_message(-1001567215170, msg)
    
    
    client.start()
    client.run_until_disconnected()
    

    我看了一下这个装饰器就是调用 client.add_event_handler,不用装饰器的话可以直接添加,用的话有什么办法吗

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   920 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:50 · PVG 04:50 · LAX 13:50 · JFK 16:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.