The Python script telegram_group_counter.py
allows you to programmatically count the number of Telegram groups you're a member of using the Telegram API and the Telethon library.
- Python
>=3.6
- Telegram API credentials (
api_id
andapi_hash
)
- Clone this repository:
git clone https://github.com/pcaversaccio/telegram-group-counter.git
cd telegram-group-counter
- Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`.
- Install the required packages:
pip install -r requirements.txt
- Create a
.env
file in the project root and add your Telegram API credentials1:
API_ID="your_api_id"
API_HASH="your_api_hash"
PHONE_NUMBER="your_phone_number"
Caution
Make sure to keep your .env
file secure and never commit it to version control!
Run the script using Python:
python scripts/telegram_group_counter.py
The script will output the number of Telegram groups you're a member of 🫡.
You are in 123 Telegram groups.
Footnotes
-
To get the Telegram API credentials go to
my.telegram.org
and log in with your phone number. Now click onAPI development tools
and create a new application by filling in the required fields. Once created, you'll see yourapi_id
(a number) andapi_hash
(a string). ↩