This commit is contained in:
= 2025-09-20 08:49:13 +02:00
parent 57e97eb358
commit d6de10e6da

View file

@ -217,13 +217,12 @@ ytdl_format_options = {
"format": "bestaudio/best",
"cookiefile": "/app/cookies.txt",
"extractor_args": {
"youtube": {
"player_client": ["android", "web"],
}
"youtube": {"player_client": ["android"]}
},
"noplaylist": True,
"quiet": True,
}
ffmpeg_options = {
"before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5",
"options": "-vn -ar 48000 -ac 2 -b:a 192k", # Optimized audio for Discord
@ -277,7 +276,6 @@ async def leave(ctx):
await ctx.voice_client.disconnect()
else:
await ctx.send("I am not in a voice channel!")
@bot.command(name="play")
async def play(ctx, *, url):
"""Streams Audio von einer YouTube URL"""
@ -288,15 +286,33 @@ async def play(ctx, *, url):
await ctx.send("Du bist in keinem Sprachkanal!")
return
player, error = await YTDLSource.from_url(url, loop=bot.loop, stream=True)
if error or not player:
await ctx.send("⚠️ Konnte den Titel nicht abspielen. "
"YouTube Restrictions blockieren möglicherweise den Zugriff.")
try:
player, error = await YTDLSource.from_url(url, loop=bot.loop, stream=True)
except Exception as e:
# Alle Fehler abfangen, z.B. DownloadError oder RuntimeError
await ctx.send(
"⚠️ Konnte den Titel nicht abspielen. "
"YouTube Restrictions oder Format-Probleme blockieren möglicherweise den Zugriff."
)
return
ctx.voice_client.stop()
if error or not player:
await ctx.send(
"⚠️ Konnte den Titel nicht abspielen. "
"YouTube Restrictions blockieren möglicherweise den Zugriff."
)
return
# Stoppe ggf. laufenden Player
if ctx.voice_client.is_playing():
ctx.voice_client.stop()
ctx.voice_client.play(player)
# Fallback für den Titel, falls None
title = getattr(player, "title", "Unbekanntes Lied")
# Buttons für Steuerung
stop_button = Button(label="Stop", style=discord.ButtonStyle.red)
pause_button = Button(label="Pause", style=discord.ButtonStyle.gray)
resume_button = Button(label="Resume", style=discord.ButtonStyle.green)
@ -325,7 +341,8 @@ async def play(ctx, *, url):
view.add_item(pause_button)
view.add_item(resume_button)
await ctx.send(f"🎶 Now playing: **{player.title}**", view=view)
await ctx.send(f"🎶 Now playing: **{title}**", view=view)
@bot.command(name="stop", help="Stop the music.")
async def stop(ctx):