Ошибка в discord.py, не понимаю как исправить
import discord
import asyncio
import requests
import urllib.parse
from bs4 import BeautifulSoup
intents = discord.Intents().all()
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print('Logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('/play'):
search = message.content[6:]
query = urllib.parse.quote(search)
url = f"https://www.youtube.com/results?search_query={query}"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
vid = soup.find_all('a', class_='yt-uix-tile-link')[0]
video_url = 'https://www.youtube.com' + vid['href']
channel = message.author.voice.channel
voice = await channel.connect()
source = await discord.FFmpegOpusAudio.from_probe(video_url)
voice.play(source)
while voice.is_playing():
await asyncio.sleep(1)
await voice.disconnect()
client.run('TOKEN') ```
При выполнении команды /play (название музыки)
Выдает ошибку:
Traceback (most recent call last):
File "C:\Users\artem\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "c:\bot.py", line 25, in on_message
vid = soup.find_all('a', class_='yt-uix-tile-link')[0]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range ```
Источник: Stack Overflow на русском