我正在尝试用Discord.py 1.3.2做音乐不和谐机器人。
作为我的队列,我只使用普通列表。List保存.mp3文件的路径。Self.vc是语音客户端。一切正常,直到歌曲结束。我试着自己解决这个问题,但是我找不到答案。怎么叫下一首“歌”?
self.source = FFmpegPCMAudio(self.queue[0])
self.vc.play(self.source, after= what should be here?)我正在阅读参考资料,我不明白"(Callable[Exception,Any])“是什么意思。
感谢您的帮助!
发布于 2020-03-30 20:25:24
由于我刚刚遇到了同样的问题,下面是我的解决方案。
Discord.Py接口提供了带有相同问题here的常见问题解答。
基本上,您定义了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)我的完整机器人是here。
https://stackoverflow.com/questions/60842161
复制相似问题