Telegram Bot for lottery game
Budget: $10 – $30 USD
Need create telegram bot to be able make lottery game.
Here's the complete translation of all Russian content into English:
### What is the `.env` file?
The `.env` file is a **configuration file** that stores sensitive environment variables for your application. It's created **manually** in your bot's directory.
---
### Step 1: Creating the `.env` file
1. **On your server** (PythonAnywhere/VPS/local PC):
- Navigate to your bot folder (e.g., `~/lottery_bot`)
- Create the file:
```bash
touch .env
```
- Open it:
```bash
nano .env
```
2. **On PythonAnywhere**:
- Go to **Files** section
- Click **New File** → name it `.env`
---
### Step 2: File contents
Add these lines (replace values with yours):
```env
# Required parameters
TELEGRAM_BOT_TOKEN=your_bot_token_from_BotFather
ADMIN_ID=your_telegram_id
CHANNEL_ID=@hamroz-lotto
# Optional
TIMEZONE=Asia/Tashkent
PAYMENT_CARD=8600123456789010
```
> **Important!**
> - `TELEGRAM_BOT_TOKEN` from [@BotFather](https://t.me/BotFather)
> - `ADMIN_ID` from [@userinfobot](https://t.me/userinfobot)
> - `CHANNEL_ID` = your channel username (`@hamroz-lotto`)
---
### Step 3: Format requirements
- **No spaces** around `=`
- **No quotes** (`"` or `'`)
- Each variable on **new line**
- Comments start with `#`
Correct example:
```env
# Hamroz lottery bot
TELEGRAM_BOT_TOKEN=6123456789:AAFAbcdefgHIJKLMNOPQRstuvwxyz123456
ADMIN_ID=558899001
CHANNEL_ID=@hamroz-lotto
```
---
### Step 4: Securing the file
1. Restrict access:
```bash
chmod 600 .env # Only owner can read/write
```
2. Prevent Git leaks (add to `.gitignore`):
```gitignore
.env
```
---
### Where to find the file
| Platform | Typical Path |
|----------------|---------------------------------------|
| PythonAnywhere | `/home/your_username/lottery_bot/.env` |
| Windows PC | `C:\Projects\lottery_bot\.env` |
| Linux VPS | `~/lottery_bot/.env` |
---
### Verification test
Add this to `bot.py`:
```python
import os
print("Token:", os.getenv("TELEGRAM_BOT_TOKEN"))
```
You should see your token when starting the bot.
---
### Troubleshooting
1. **File not loading**:
- Add to top of `bot.py`:
```python
from dotenv import load_dotenv
load_dotenv() # Loads .env
```
2. **Permission errors**:
```bash
ls -la .env # Should show -rw-------
```
3. **Variable issues**:
- Check for typos (e.g., `TELEGRAM_BOT_TOKEN` ≠ `TELEGRAM_BOT_TOKЕN`)
- Restart bot after changes
For further help:
1. Share `.env` screenshot (hide sensitive data)
2. Provide error logs
3. Confirm file location with:
```bash
pwd && ls -la .env
```
Here's the complete translation of all Russian content into English:
### What is the `.env` file?
The `.env` file is a **configuration file** that stores sensitive environment variables for your application. It's created **manually** in your bot's directory.
---
### Step 1: Creating the `.env` file
1. **On your server** (PythonAnywhere/VPS/local PC):
- Navigate to your bot folder (e.g., `~/lottery_bot`)
- Create the file:
```bash
touch .env
```
- Open it:
```bash
nano .env
```
2. **On PythonAnywhere**:
- Go to **Files** section
- Click **New File** → name it `.env`
---
### Step 2: File contents
Add these lines (replace values with yours):
```env
# Required parameters
TELEGRAM_BOT_TOKEN=your_bot_token_from_BotFather
ADMIN_ID=your_telegram_id
CHANNEL_ID=@hamroz-lotto
# Optional
TIMEZONE=Asia/Tashkent
PAYMENT_CARD=8600123456789010
```
> **Important!**
> - `TELEGRAM_BOT_TOKEN` from [@BotFather](https://t.me/BotFather)
> - `ADMIN_ID` from [@userinfobot](https://t.me/userinfobot)
> - `CHANNEL_ID` = your channel username (`@hamroz-lotto`)
---
### Step 3: Format requirements
- **No spaces** around `=`
- **No quotes** (`"` or `'`)
- Each variable on **new line**
- Comments start with `#`
Correct example:
```env
# Hamroz lottery bot
TELEGRAM_BOT_TOKEN=6123456789:AAFAbcdefgHIJKLMNOPQRstuvwxyz123456
ADMIN_ID=558899001
CHANNEL_ID=@hamroz-lotto
```
---
### Step 4: Securing the file
1. Restrict access:
```bash
chmod 600 .env # Only owner can read/write
```
2. Prevent Git leaks (add to `.gitignore`):
```gitignore
.env
```
---
### Where to find the file
| Platform | Typical Path |
|----------------|---------------------------------------|
| PythonAnywhere | `/home/your_username/lottery_bot/.env` |
| Windows PC | `C:\Projects\lottery_bot\.env` |
| Linux VPS | `~/lottery_bot/.env` |
---
### Verification test
Add this to `bot.py`:
```python
import os
print("Token:", os.getenv("TELEGRAM_BOT_TOKEN"))
```
You should see your token when starting the bot.
---
### Troubleshooting
1. **File not loading**:
- Add to top of `bot.py`:
```python
from dotenv import load_dotenv
load_dotenv() # Loads .env
```
2. **Permission errors**:
```bash
ls -la .env # Should show -rw-------
```
3. **Variable issues**:
- Check for typos (e.g., `TELEGRAM_BOT_TOKEN` ≠ `TELEGRAM_BOT_TOKЕN`)
- Restart bot after changes
For further help:
1. Share `.env` screenshot (hide sensitive data)
2. Provide error logs
3. Confirm file location with:
```bash
pwd && ls -la .env
```