的队列中的自动化蟒蛇不和谐的机器人

0

的问题

这是代码,我有:

@commands.command(pass_context=True, aliases= ["aq"])
async def add_queue(self, ctx, *, url):
  a = ctx.message.guild.id
  b = servers[a]
  global queue
  try: 
    b[len(b)] = url 
    user = ctx.message.author.mention
    await ctx.send(f'``{url}`` was added to the queue by {user}!')
  except:
    await ctx.send(f"Couldnt add {url} to the queue!")

@commands.command(pass_context=True, aliases= ["qp"], case_insensitive=True)
async def pq(self,ctx, number):
  a = ctx.message.guild.id
  b = servers[a]
  if int(number) in b:
    source = b[int(number)]
    self.cur_song_id = int(number)
    await ctx.send(f"**Now Playing:** {source}")
    await self.transformer(ctx, source)
    
async def transformer(self,ctx, url):
  player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=True)
  if not ctx.message.author.voice:
    await ctx.send("You are not connected to a voice channel!")
    return
  elif ctx.voice_client and ctx.voice_client.is_connected():
    print('Already connected to voice')
    pass
  else:
    channel = ctx.message.author.voice.channel
    await ctx.send(f'Connected to ``{channel}``')
    await channel.connect()
  ctx.voice_client.play(player)

我可以创建一个单独的队列中的每一个服务器并加入歌曲给它的命令:

-aq song_name

例队列:

Your current queue is {0: 'abcdefu', 1: 'stereo hearts', 2: 'shivers'}

我可以玩的歌曲在队列命令:

-pq 0 or -pq 1 or -pq 2

但问题是,机器人只扮演一首歌曲和后停止它的完成,和我想的机器人玩下一首歌之后的前歌曲完成和保持下去,直到最后一首歌在队列中。

请帮助我。

在此先感谢!!!

2
0

首先,你的词典({0: 'abcdefu', 1: 'stereo hearts', 2: 'shivers'})真的可以只是一个列表,因为钥匙基本上只是指标。

其次,我没有任何经验与音频中 discord.py 但它似乎喜欢你 pq 功能并不实际走向下一首歌曲。 它呼吁 transformer 功能的一次,那是它。 似乎真的你所要做的只是通过环队列并发挥的每一首歌曲。 这里是一些psuedocode,可能是有帮助:

@commands.command()
async def play_queue(self,ctx,number=0):
  for num in range(number,len(queue)):
    song = queue[num]
    # play the song

违约 number=0 将允许对整个队列发挥,如果没有数量规定。

2021-11-23 18:41:58

嗨,首先,对不起,回答这么晚了,笔记本电脑打破了。 无论如何,我试图这样做。 问题是,循环不会等待第一首歌完成的,它只是递增的迭代,同时第一首歌还是玩的,这就给出了一个错误说、音频已经播放。
xBatmanx

啊好我明白了。 有一个参数的 play 功能叫 after(discordpy.readthedocs.io/en/latest/...). 它的目的是为错误处理,但它似乎是使用通常要么重复了一首歌或起另外一个。 还检查了这个 帖子. 它显示了一个非常简单的方式来使用 after 参数,适合你的情况
Roopesh-J

是的,我实际上想出来那天晚上!. 谢谢你把在努力帮助! 真的很感激。
xBatmanx

最好的答案

0

因此,要解决我的问题,我实现这个代码和它的工作。

我通过我的队列,这是一个典、变压器的功能,以及一些其是拖欠为0(进队列中发挥的开始)。

和使用 after 参数在发挥功能,我一直打电话的功能和保持迭代的数量,只要它是小于长的队列。

它自扮演的歌曲在队列中。

我知道这代码的工作,但是,如果任何可以改进,我是开放的建议。

async def transformer(self,ctx, number, que):
  player = await YTDLSource.from_url(que[number], loop=self.bot.loop,stream=True)
  await ctx.send(f"**Now Playing:** {que[number]}")
  ctx.voice_client.play(player, after=lambda e: asyncio.run_coroutine_threadsafe(self.transformer(ctx,number+1 , que),self.bot.loop) if number < len(que) else ctx.voice_client.pause())

谢谢.

2021-12-03 06:39:41

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................