큐 자동화 파이썬에서 불화 로봇

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/최/...). 그것은 오류 처리를 위해 그러나 그것은 보인다 그것은 일반적으로 사용하거나 반복 노래하거나 재생 또 다른 하나입니다. 또한 체크 아웃이 post. 그것을 보여줍니다 정말 간단한 방법을 사용하여 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ý
..................................................................................................................