Python 如何在discord.py中循环播放音乐?

Python 如何在discord.py中循环播放音乐?,python,discord.py,Python,Discord.py,如何在discord.py中循环播放音乐? 我目前的代码是: 我只想循环一首歌曲,而不是一个队列中的歌曲,但我不知道如何做到这一点。 我在stackoverflow/youtube上搜索过类似的问题,但什么也没找到。 有人能给我提供代码吗?这能回答你的问题吗?没有,我不知道为什么,但代码就是不起作用。没有错误,只是不循环。已尝试更改代码。 TOKEN = 'my token that im not gonna share here :D' import discord from discord

如何在discord.py中循环播放音乐? 我目前的代码是:

我只想循环一首歌曲,而不是一个队列中的歌曲,但我不知道如何做到这一点。 我在stackoverflow/youtube上搜索过类似的问题,但什么也没找到。
有人能给我提供代码吗?

这能回答你的问题吗?没有,我不知道为什么,但代码就是不起作用。没有错误,只是不循环。已尝试更改代码。
TOKEN = 'my token that im not gonna share here :D'

import discord
from discord.ext import commands
import youtube_dl
import os
import nacl

client = commands.Bot(command_prefix="*")

@client.event
async def on_ready():
    print('ready')

@client.command()
async def join(ctx):
    voiceChannel = discord.utils.get(ctx.guild.voice_channels, name='music custombot')
    await voiceChannel.connect()

@client.command()
async def play(ctx, url : str):
    song_there = os.path.isfile("song.mp3")
    if song_there:
     os.remove('song.mp3')

    voice = discord.utils.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:
        ydl.download([url])
    for file in os.listdir("./"):
        if file.endswith(".mp3"):
            os.rename(file, "song.mp3")
    voice.play(discord.FFmpegPCMAudio("song.mp3"))

client.run(TOKEN)