https://github.com/nitanmarcel/tlmulticlient
Multi Sessions addon for Telethon
https://github.com/nitanmarcel/tlmulticlient
Last synced: 6 months ago
JSON representation
Multi Sessions addon for Telethon
- Host: GitHub
- URL: https://github.com/nitanmarcel/tlmulticlient
- Owner: nitanmarcel
- License: mit
- Created: 2020-01-06T20:22:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-18T09:36:47.000Z (about 4 years ago)
- Last Synced: 2024-11-16T07:48:01.955Z (7 months ago)
- Language: Python
- Size: 7.81 KB
- Stars: 7
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Multi Sessions addon for Telethon
## This project might not work 100%, use this more as a reference project rather than an working library. The MIT license should make it easy for you to use parts of the code here in your own projects
## Installing:
```bash
pip3 install tlmulticlient
```## How to use:
```python
# importing multiclient library and other required imports
from tlmulticlient import MultiClient
import asyncio
from telethon import events
# create the multiclientclient = MultiClient(api_id=12345, api_hash='my_api_hash', sessions=['list', 'of', 'str_sessions'])
# listenting to new messages
@client.on(events.NewMessage)
def listener(event):
# Now we need to use `event.client.etc` instead of client.etc to be able to run a function on all the available clients!
await event.client.send_message(event.chat_id, "Hello World!")# To find out from which session an event was triggered we use:
id = event.client.session_id # session id is the name of the session attached to the client which received the event.
if id == 'str_sessions':
print('This event was triggered from the session named str_sessions')
else:
print('This event was triggered from the session named {0}'.format(id))# iterate though all the clients
for c in client:
print(c.session_id)# run all the clients
loop = asyncio.get_event_loop()
client.run_all_clients(loop=loop)
```