Follow the below steps to make any repository deployable
1. Add the requirements given below to your "requirements.txt" file
pytz
Flask
aiohttp
gunicorn
Jinja2
werkzeug
itsdangerous
2. Create a new file named "app.py" and enter the code given below
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'TechifyBots'
if __name__ == "__main__":
app.run()
3. Now, replace the code in your existing "bot.py" or "main.py" file with the code provided below.
import os
from datetime import datetime
from pytz import timezone
from pyrogram import Client
from aiohttp import web
from config import API_ID, API_HASH, BOT_TOKEN, ADMIN, LOG_CHANNEL
routes = web.RouteTableDef()
@routes.get("/", allow_head=True)
async def root_route(request):
return web.Response(text="I am Alive", content_type='text/html')
async def web_server():
app = web.Application(client_max_size=30_000_000)
app.add_routes(routes)
return app
class Bot(Client):
def __init__(self):
super().__init__(
"techifybots",
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN,
plugins=dict(root="plugins"),
workers=200,
sleep_threshold=15
)
async def start(self):
app = web.AppRunner(await web_server())
await app.setup()
try:
await web.TCPSite(app, "0.0.0.0", int(os.getenv("PORT", 8080))).start()
print("Web server started.")
except Exception as e:
print(f"Web server error: {e}")
await super().start()
me = await self.get_me()
print(f"Bot Started as {me.first_name}")
if isinstance(ADMIN, int):
try:
await self.send_message(ADMIN, f"**{me.first_name} is started...**")
except Exception as e:
print(f"Error sending message to admin: {e}")
if LOG_CHANNEL:
try:
now = datetime.now(timezone("Asia/Kolkata"))
msg = (
f"**{me.mention} is restarted!**\n\n"
f"📅 Date : `{now.strftime('%d %B, %Y')}`\n"
f"⏰ Time : `{now.strftime('%I:%M:%S %p')}`\n"
f"🌐 Timezone : `Asia/Kolkata`"
)
await self.send_message(LOG_CHANNEL, msg)
except Exception as e:
print(f"Error sending to LOG_CHANNEL: {e}")
async def stop(self, *args):
await super().stop()
print(f"{me.first_name} Bot stopped.")
Bot().run()
4. Create a new file name "run cmd.txt"
gunicorn app:app & "YOUR_RUN_CMD"
gunicorn app:app & python3 bot.py
Important
If you still face any issue then click on the below button
Copying the post and using it without permission is strictly prohibited.