youtube_dl stuck on "downloading webpage" when trying to run Discord Bot
I am trying to create a Discord music bot using Python, and when running my bot's code through the terminal, the bot successfully joins the channel I am in and recognizes that there was a link from Youtube that it needs to play.
However, the bot is for some reason stuck in the terminal on 'downloading webpage' and never loads through yet also never throws an error. I am unsure of what I need to fix or need to add.
An example of what it says is: [youtube] IOatp-OCw3E: Downloading webpage
All of the code for my bot is here:
import youtube_dl
import os
import asyncio
import nacl
client = discord.Client()
token = 'REMOVED FOR PRIVACY'
voice_clients = {}
yt_dl_opts = {'format': 'bestaudio/best'}
ytdl = youtube_dl.YoutubeDL(yt_dl_opts)
ffmpeg_options = {'options': '-vn'}
@client.event
async def on_ready():
print(f"Bot logged in as {client.user}")
@client.event
async def on_message(msg):
if msg.content.startswith('//play'):
try:
url = msg.content.split()[1]
voice_client = await msg.author.voice.channel.connect()
voice_clients[voice_client.guild.id] = voice_client
loop = asyncio.get_event_loop()
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=False))
song = data['url']
player = discord.FFmpegPCMAudio(song, **ffmpeg_options, executable='/Users/sethstevens/audio-orchestrator-ffmpeg/bin/ffmpeg')
voice_client.play(player)
except Exception as err:
print(err)
client.run(token)
I currently only have the '//play' command done and will finish the others when my bot can actually play the link given.
Comments
Post a Comment