如何在 discord.py 中循环播放音乐? 我当前的代码是:
<块引用>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)
我只想循环播放 1 首歌曲,而不是包含歌曲的队列,但是我不知道如何执行此操作。 我在 stackoverflow/youtube 上搜索过类似的问题,但是我找不到任何东西。 有人可以给我提供代码吗?