【问题标题】:Discord music bot - error with ffpmeg player and embed messageDiscord 音乐机器人 - ffpmeg 播放器和嵌入消息出错
【发布时间】:2021-04-21 13:43:38
【问题描述】:

我想在 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)

【问题讨论】:

  • 如果您向我们展示您遇到的错误会更好。
  • 这就是它所显示的。 “RuntimeWarning:从未等待协程‘Main.player_now’”。我认为,问题出在 ctx.voice_client.play after=lambda 上。但我不知道,如何解决这个问题

标签: python discord discord.py discord.py-rewrite


【解决方案1】:

这可能与您需要等待的事实有关

ctx.voice_client.play
.play

是一个协程,这意味着你需要等待它。改成

await ctx.voice_client.play

【讨论】:

  • 是的,没错,但它想要这样的东西:“ctx.voice_client.play(discord.FFmpegPCMAudio(queue_url[i], **FFMPEG_OPTS), after= lambda e: await self. player_now(ctx))”。但这无法完成,因为它显示错误“SyntaxError: 'await' outside async function”。
猜你喜欢
  • 2022-01-21
  • 2021-05-05
  • 1970-01-01
  • 2022-01-04
  • 1970-01-01
  • 2018-07-24
  • 2020-09-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多