123456789101112131415161718192021222324252627282930313233 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- from telethon.events import NewMessage
- from telethon.sync import TelegramClient
- from telethon.tl.types import PeerChannel
- import config
- def main():
- bot = TelegramClient('bot', config.API_ID, config.API_HASH)
- def is_channel(event) -> bool:
- return isinstance(event.message.peer_id, PeerChannel)
- @bot.on(NewMessage(incoming=True, func=is_channel))
- async def handler(event):
- print(event.message.peer_id)
- await bot.disconnect()
- bot.start(bot_token=config.TOKEN)
- print(
- 'started.\n'
- 'waiting for message...'
- )
- bot.run_until_disconnected()
- if __name__ == '__main__':
- main()
|