0

Вот код, подскажите как сделать чтобы музыка играла бесконечно, пока я ее сам не остановлю.

Напишите что добавить пожалуйста, буду благодарен

@client.command(pass_context=True, aliases=['u', 'ur'])
async def url(ctx, url: str):

    song_there = os.path.isfile("song.mp3")
    try:
        if song_there:
            os.remove("song.mp3")
            print("Removed old song file")
        await ctx.send("Бот загружает музыку...")
    except PermissionError:
        print("Trying to delete song file, but it's being played")
        await ctx.send("ERROR: Music playing")
        return
    await ctx.send("Почти готово...")
    voice = get(client.voice_clients, guild=ctx.guild)
    ydl_opts = {
        'format' : 'bestaudio/best',
        'postprocessors' : [{ 
            'key' : 'FFmpegExtractAudio',
            'preferredcodec' : 'mp3',
            'preferredquality' : '192'
            }],
        }
    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        print("Downloading audio now\n")
        ydl.download([url])

    for file in os.listdir("./"):
        if file.endswith(".mp3"):
            name = file
            print(f"Renamed File: {file}\n")
            os.rename(file, "song.mp3")
    voice.play(discord.FFmpegPCMAudio("song.mp3"), after=lambda e: print("Song done!")) 
    await ctx.send("Готово!") 
    voice.source = discord.PCMVolumeTransformer(voice.source)
    voice.source.volume = 0.09

    nname = name.rsplit("-", 2)
    await ctx.send(f"**Играет трек**: {nname[0]}")
    print("playing\n")

1 ответ 1

1

попробуй discord.FFmpegPCMAudio("song.mp3", before_options="-stream_loop -1")

2
  • не помогло( Куда именно вставить? может я туплю
    – Flaky
    23 июл 2021 в 22:37
  • все работает, я просто затупил, спасибо!
    – Flaky
    24 июл 2021 в 11:23

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.