Talablarga ko'ra :
import telebot
from apiclient.discovery import build
api_key = 'your_api_key'
bot = telebot.TeleBot('your_bot_token')
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Assalomu alaykum! Qoshiq nomidan qidiruv uchun /qoshiq buyrug'ini yuboring")
@bot.message_handler(commands=['qoshiq'])
def search_song(message):
search_query = message.text[8:]
youtube = build('youtube', 'v3', developerKey=api_key)
request = youtube.search().list(
part='snippet',
maxResults=1,
q=search_query + ' music video'
)
response = request.execute()
video_id = response['items'][0]['id']['videoId']
bot.reply_to(message, f"https://www.youtube.com/watch?v={video_id}")
bot.polling()
Telegram bot ✅✅
import telebot
from apiclient.discovery import build
api_key = 'your_api_key'
bot = telebot.TeleBot('your_bot_token')
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Assalomu alaykum! Qoshiq nomidan qidiruv uchun /qoshiq buyrug'ini yuboring")
@bot.message_handler(commands=['qoshiq'])
def search_song(message):
search_query = message.text[8:]
youtube = build('youtube', 'v3', developerKey=api_key)
request = youtube.search().list(
part='snippet',
maxResults=1,
q=search_query + ' music video'
)
response = request.execute()
video_id = response['items'][0]['id']['videoId']
bot.reply_to(message, f"https://www.youtube.com/watch?v={video_id}")
bot.polling()
Telegram bot ✅✅