我建立了一个(简单的)排队系统,其中在机器人已经在播放音乐的同时添加的歌曲将添加到队列中,并在完成后播放。但是,当我在正在播放的同时添加音乐时,当前歌曲会停止。
@commands.command()
async def play(self, ctx, *, url):
# url
added = False # so i can avoid code later
if ctx.voice_client.is_playing() or queue:
queue.append(url)
temp = await YTDLSource.from_url(queue[-1], loop=self.bot.loop)
queueNames.append(f"{temp.title}") # displaying youtube name rather than user's search
added = True # this is for later
else:
try:
queue.pop(0) # if it's not playing, get rid of old song
queueNames.pop(0)
except:
pass # if there is no old song, do nothing
queue.append(url)
temp = await YTDLSource.from_url(queue[-1], loop=self.bot.loop)
queueNames.append(f"{temp.title}")
if not added: # if no new songs were added
async with ctx.typing():
player = await YTDLSource.from_url(queue[0], loop=self.bot.loop)
ctx.voice_client.play(player, after=lambda e: print("Player error: %s" % e) if e else None)
await ctx.send(f"Now playing {player.title}")
else:
await ctx.send(f"{temp.title} added to the queue") # simple message
没有错误,只是停止播放当前歌曲。假设我正在演奏《粉碎的嘴》,然后尝试排队,永远不要让你放弃,机器人将停止播放,我必须做*skip
才能开始我排队的下一首歌曲。
另外,当歌曲结束时,它不会直接进入我排队的下一首歌曲。