nikanfarokhi2/Nikplayer_BotPublic · Bot Template

AIThe pasted code is a Python Pyrogram bot intended to play music and video in Telegram groups and channels using PyTgCalls. It uses yt_dlp to search YouTube and extract direct stream URLs, supporting audio-only or combined audio/video playback. The code includes placeholder API credentials and is an incomplete bot skeleton rather than a working TBL command.

Entertainmentnot_tblpythonpyrogrampytgcallsmusicvideo
ProfileTelegram
1 commands0 envUpdated 5d agoCreated Jul 28, 2026
Back to folder

commands/_Start.js

javascript · 106 lines

Raw
1/**#command2name: /Start3answer: یه ربات برام بساز که توانایی پخش موزیک صوتی و تصویری رو داشته باشه و همچنین بتونم ازش داخل گروه های تلگرام و کانال ها استفاده کنم4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12import asyncio13from pyrogram import Client, filters14from pyrogram.types import Message15from pytgcalls import PyTgCalls16from pytgcalls.types import AudioVideoPiped, AudioPiped17import yt_dlp18 19# ---------------- تنظیمات ربات ----------------20API_ID = 1234567          # API ID خود را اینجا وارد کنید21API_HASH = "YOUR_API_HASH"  # API Hash خود را اینجا وارد کنید22BOT_TOKEN = "YOUR_BOT_TOKEN" # توکن ربات خود را اینجا وارد کنید23# ---------------------------------------------24 25app = Client("music_video_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)26call = PyTgCalls(app)27 28def search_yt(query: str, video: bool = False):29    """جستجوی لینک مستقیم پخش از یوتیوب یا لینک مستقیم ورود"""30    ydl_opts = {31        'format': 'bestvideo+bestaudio/best' if video else 'bestaudio/best',32        'quiet': True,33        'no_warnings': True,34    }35    with yt_dlp.YoutubeDL(ydl_opts) as ydl:36        # اگر لینک مستقیم نبود، در یوتیوب سرچ می‌کند37        if not query.startswith("http"):38            query = f"ytsearch:{query}"39        info = ydl.extract_info(query, download=False)40        if 'entries' in info:41            info = info['entries'][0]42        return info['url'], info.get('title', 'نامشخص')43 44@app.on_message(filters.command("play") & (filters.group | filters.channel))45async def play_audio(client: Client, message: Message):46    """دستور پخش موزیک صوتی"""47    chat_id = message.chat.id48    query = " ".join(message.command[1:])49    50    if not query:51        await message.reply_text("❌ لطفا نام آهنگ یا لینک آن را وارد کنید.\nمثال: `/play آهنگ جدید`")52        return53 54    msg = await message.reply_text("🔍 در حال جستجو و آماده‌سازی صوت...")55    try:56        stream_url, title = search_yt(query, video=False)57        58        # پیوستن به ویس چت و پخش صوت59        await call.join_group_call(60            chat_id,61            AudioPiped(stream_url)62        )63        await msg.edit_text(f"🎶 **در حال پخش صوتی:**\n‏`{title}`")64    except Exception as e:65        await msg.edit_text(f"❌ **خطا در پخش:**\n`{str(e)}`\n*(مطمئن شوید ویس چت گروه روشن است)*")66 67@app.on_message(filters.command("vplay") & (filters.group | filters.channel))68async def play_video(client: Client, message: Message):69    """دستور پخش ویدیو (تصویری)"""70    chat_id = message.chat.id71    query = " ".join(message.command[1:])72    73    if not query:74        await message.reply_text("❌ لطفا نام ویدیو یا لینک آن را وارد کنید.\nمثال: `/vplay موزیک ویدیو`")75        return76 77    msg = await message.reply_text("🔍 در حال جستجو و آماده‌سازی ویدیو...")78    try:79        stream_url, title = search_yt(query, video=True)80        81        # پیوستن به ویس چت و پخش ویدیو + صوت82        await call.join_group_call(83            chat_id,84            AudioVideoPiped(stream_url)85        )86        await msg.edit_text(f"🎬 **در حال پخش تصویری:**\n‏`{title}`")87    except Exception as e:88        await msg.edit_text(f"❌ **خطا در پخش ویدیو:**\n`{str(e)}`\n*(مطمئن شوید ویس چت گروه روشن است)*")89 90@app.on_message(filters.command("stop") & (filters.group | filters.channel))91async def stop_stream(client: Client, message: Message):92    """دستور توقف پخش و خروج از ویس چت"""93    try:94        await call.leave_group_call(message.chat.id)95        await message.reply_text("⏹ **پخش متوقف شد و ربات از ویس‌چت خارج گردید.**")96    except Exception as e:97        await message.reply_text(f"❌ **خطا:** `{str(e)}`")98 99async def main():100    await app.start()101    await call.start()102    print("🤖 ربات با موفقیت روشن شد!")103    await asyncio.Event().wait()104 105if __name__ == "__main__":106    asyncio.run(main())