Discord.py-VoiceClient.如何调用下一个音频文件?播放(source,*,after=None)



我正在尝试使用discord.py 1.3.2制作音乐不和机器人。

作为我的队列,我只是使用普通列表。列表保留.mp3文件的路径。Self.vc是语音客户端。一切都很好,直到歌曲结束。我试着自己想办法,但找不到答案。如何称呼下一首"歌曲"?

self.source = FFmpegPCMAudio(self.queue[0])
self.vc.play(self.source, after= what should be here?)

我正在阅读参考资料,我不明白"(可调用[[异常],任意]("是什么意思。

谢谢你的帮助!

由于我刚刚遇到了同样的问题,这里是我的解决方案。

不和。Py API在这里提供了一个相同问题的常见问题解答。

基本上,您定义了after函数,并使用asyncio.run_coroutine_threadsafe来调用所有内容。

这是我的代码:

def playit():
try:
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(gPlaylist[0]), gVol)
bot.voice_clients[0].play(source, after = myafter)
gPlaylist.pop(0)
except Exception as e:
print(e)
def myafter(error):
try:
fut = asyncio.run_coroutine_threadsafe(playit(), bot.loop)
fut.result()
except Exception as e:
print(e)
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(gPlaylist[0]), gVol)
ctx.voice_client.play(source, after = myafter)

我的完整机器人在这里。

最新更新