我有一个机器人,该机器人应该在队列中移动并通过语音客户端播放歌曲。播放完歌曲后,应使用check_queue
来取出列表中的第一首歌曲,以便继续播放下一首歌曲。但是,该方法看起来好像运行了两次,这意味着它将取出两首歌曲而不是一首。
@commands.command()
async def q(self, ctx, *, url):
channel = discord.utils.get(ctx.guild.voice_channels, name="Melodies of Arts")
if ctx.voice_client is None:
await channel.connect()
def check_queue(error):
if(len(queues[ctx.guild.id]) != 0):
print("poppin off")
player = queues[ctx.guild.id].pop(0)
ctx.voice_client.play(player, after=check_queue)
async with ctx.typing():
player = await YTDLSource.from_url(url, loop=self.bot.loop)
if ctx.guild.id in queues:
queues[ctx.guild.id].append(player)
else:
queues[ctx.guild.id] = [player]
await ctx.send("Video __" + str(player.title) + "__" + " queued at **Position #" + str(len(queues[ctx.guild.id])) + "**", delete_after=15)
if(not ctx.voice_client.is_playing()):
print("not playing,moving on")
ctx.voice_client.play(player, after=check_queue)
await ctx.send('***Now playing:*** __{}__'.format(player.title), delete_after=10)
我确保机器人没有同时运行两个实例。我不知道after
函数中的play
参数是否正在运行两次,但是我无法确定这一点。
答案 0 :(得分:0)
因此,原来是我的命令列出了问题所在的队列。修复与此相关的代码似乎已经解决了问题。