我想在 Python 中为 Discord 创建一个带有队列的音乐机器人,但是每次运行时,都会弹出一个错误。有人可以告诉我,这段代码有什么问题吗?谢谢。
def player(self, ctx):
FFMPEG_OPTS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
global i
if i < len(queue_url):
ctx.voice_client.play(discord.FFmpegPCMAudio(queue_url[i], **FFMPEG_OPTS), after= lambda e: self.player_now(ctx))
i = i+1
async def player_now(self, ctx):
global i
await self.info_now(ctx)
self.player(ctx)
async def info_now(self, ctx):
embed = discord.Embed(color=0x00ff00)
embed.title = "Playing now"
embed.description = queue_title[i]
await ctx.send(embed=embed)
答案 0 :(得分:0)
这可能与您需要等待这一事实有关
ctx.voice_client.play
.play
是一个协程,这意味着你需要等待它。改成
await ctx.voice_client.play