当我使用我的skip命令时,我的程序停止播放音乐,而不是跳过歌曲。 这是代码:
queues = {}
players = {}
opts = {
'default_search': 'auto',
'quiet': True,
}
voice_states = {}
class voice:
def __init__(self, client):
self.client = client
@commands.command(pass_context=True)
async def skip(self, ctx):
id = ctx.message.server.id
players[id].stop()
@commands.command(
pass_context=True
)
async def play(self, ctx, url):
server = ctx.message.server
channel = ctx.message.author.voice.voice_channel
try:
await self.client.join_voice_channel(channel)
except:
print(" ")
if server.id not in players or players[server.id].is_done():
server = ctx.message.server
voice_client = self.client.voice_client_in(server)
player = await voice_client.create_ytdl_player(url, after=lambda: queue(server.id), ytdl_options=opts)
players[server.id] = player
await self.client.say('Now Playing ' )
player.start()
else:
server = ctx.message.server
voice_client = self.client.voice_client_in(server)
player = await voice_client.create_ytdl_player(url, after=lambda: queue(server.id), ytdl_options=opts)
if server.id in queues:
queues[server.id].append(player)
else:
queues[server.id] = [player]
await self.client.say('Now Playing ' )
await self.client.say('Video queued.')
def queue(self, id):
if queues[id] != []:
player = queues[id].pop(0)
players[id] = player
player.start()
def setup(client):
client.add_cog(voice(client))
我没有收到错误代码, 只是没有队列。 修复了我的代码或自己的解决方案。 抱歉,很长的代码,但是您需要所有上下文