从本地文件夹播放mp3音乐?不和谐.py



我想让我的机器人一首接一首地播放多首歌曲。我所拥有的只是我的机器人播放一首歌,然后停下来做。到目前为止我的代码:

@bot.command()
async def startq(ctx):
channel = bot.get_channel(705831663497904211)
vc = await channel.connect()
vc.play(discord.FFmpegPCMAudio("E:ProgrammierenProgrammierenDisc-Botmusic2.mp3"))

您应该在songs列表中添加您想要的歌曲,然后它应该播放所有歌曲。

您还可以扫描文件夹中的所有文件,并使用glob将它们添加到列表中。

注意:我还没有尝试过,但理论上应该可以。

import glob
@bot.command()
async def startq(ctx):
channel = bot.get_channel(705831663497904211)
vc = await channel.connect()

songs = ["music2.mp3","music1.mp3"]
# or check all files in folder
songs = glob.glob("E:ProgrammierenProgrammierenDisc-Bot*.mp3")
for song in songs:
vc.play(discord.FFmpegPCMAudio(f"E:ProgrammierenProgrammierenDisc-Bot{song}"))
while vc.is_playing():
await asyncio.sleep(1)

最新更新