admin管理员组文章数量:1320661
Trying to play a youtube video as audio through a discord bot. I ran into a 403 forbidden error and added the YDL_OPTIONS to bypass this. Now the code throws the error code 3436169992.The bot writes to the server "now playing: xxxx" but no audio is played. Any pointers?
FFMPEG_OPTIONS = {
"before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5",
"options": "-vn -filter:a \"volume=0.25\""
}
# yt-dlp options
YDL_OPTIONS = {
"format": "bestaudio[ext=webm][acodec=opus]/bestaudio",
"noplaylist": True,
"quiet": True,
"extract_flat": False,
"no_warnings": True,
"source_address": "0.0.0.0" # Prevents YouTube throttling
}
voice_clients = {}
@bot.event
async def on_message(message):
if message.content.startswith("-play"):
try:
# Ensure the user is in a voice channel
if not message.author.voice:
await message.channel.send("You need to be in a voice channel to use this command.")
return
# Connect to the user's voice channel if not already connected
if message.guild.id not in voice_clients or not voice_clients[message.guild.id].is_connected():
voice_client = await message.author.voice.channel.connect()
voice_clients[message.guild.id] = voice_client
else:
voice_client = voice_clients[message.guild.id]
# Extract the YouTube URL from the command
url = message.content.split()[1]
# Download and extract audio using yt-dlp
with YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(url, download=False)
audio_url = info["url"]
title = info.get("title", "Unknown Title")
# Debug: Print the extracted audio URL
print(f"Audio URL: {audio_url}")
# Play the audio using FFmpeg
source = FFmpegPCMAudio(audio_url, **FFMPEG_OPTIONS)
voice_client.play(source, after=lambda e: print("Playback finished."))
# Notify the user
await message.channel.send(f"Now playing: {title}")
except Exception as e:
print(f"Error: {e}")
await message.channel.send("An error occurred while trying to play the audio.")
本文标签: pythonffmpeg process 20564 successfully terminated with return code of 3436169992Stack Overflow
版权声明:本文标题:python - ffmpeg process 20564 successfully terminated with return code of 3436169992 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742065676a2418819.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论