需要帮助 Discord 机器人队列
Need help Discord bot queue
我一直在尝试为 discord 机器人创建一个队列,我的 >q
命令基本上与 join
一样工作
play
queue
同时。问题是它只能同时排队 2 首歌曲,所以我需要帮助让它排队多首歌曲
queues = {}
#check queue
def check_queue(ctx, id):
if queues[id] !=[]:
voice = ctx.guild.voice_client
voice.play(queues[id].pop(0))
#command
@client.command(pass_context = True)
async def q(ctx, url):
if (ctx.author.voice):
channel = ctx.message.author.voice.channel
voice = get(client.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
else:
await ctx.send('You are not in a voice channel')
YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'}
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
voice = get(client.voice_clients, guild=ctx.guild)
with YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(url, download=False)
URL = info['url']
source = (FFmpegPCMAudio(URL, **FFMPEG_OPTIONS))
if voice.is_playing():
guild_id = ctx.message.guild.id
if guild_id in queues:
queues[guild_id].append(source)
else:
queues[guild_id]=[source]
await ctx.send('Deemo: Song added to queue')
else:
ctx.voice_client.stop()
voice.play(FFmpegPCMAudio(URL, **FFMPEG_OPTIONS), after=lambda x=0: check_queue(ctx, ctx.message.guild.id))
voice.is_playing()
await ctx.send('Playing: '+ info.get('title'))
在我做了一些研究和搜索之后,我想出了一个简单的方法来使队列循环 2+ 首歌曲,在 check_queue
中添加 after=lambda x=0: check_queue(ctx, ctx.message.guild.id)
并稍微改变一下,它看起来像这样
def check_queue(ctx, id):
if queues[id] !=[]:
voice = ctx.guild.voice_client
source = queues[id].pop(0)
voice.play(source, after=lambda x=0: check_queue(ctx, ctx.message.guild.id))
我一直在尝试为 discord 机器人创建一个队列,我的 >q
命令基本上与 join
一样工作
play
queue
同时。问题是它只能同时排队 2 首歌曲,所以我需要帮助让它排队多首歌曲
queues = {}
#check queue
def check_queue(ctx, id):
if queues[id] !=[]:
voice = ctx.guild.voice_client
voice.play(queues[id].pop(0))
#command
@client.command(pass_context = True)
async def q(ctx, url):
if (ctx.author.voice):
channel = ctx.message.author.voice.channel
voice = get(client.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
else:
await ctx.send('You are not in a voice channel')
YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'}
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
voice = get(client.voice_clients, guild=ctx.guild)
with YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(url, download=False)
URL = info['url']
source = (FFmpegPCMAudio(URL, **FFMPEG_OPTIONS))
if voice.is_playing():
guild_id = ctx.message.guild.id
if guild_id in queues:
queues[guild_id].append(source)
else:
queues[guild_id]=[source]
await ctx.send('Deemo: Song added to queue')
else:
ctx.voice_client.stop()
voice.play(FFmpegPCMAudio(URL, **FFMPEG_OPTIONS), after=lambda x=0: check_queue(ctx, ctx.message.guild.id))
voice.is_playing()
await ctx.send('Playing: '+ info.get('title'))
在我做了一些研究和搜索之后,我想出了一个简单的方法来使队列循环 2+ 首歌曲,在 check_queue
中添加 after=lambda x=0: check_queue(ctx, ctx.message.guild.id)
并稍微改变一下,它看起来像这样
def check_queue(ctx, id):
if queues[id] !=[]:
voice = ctx.guild.voice_client
source = queues[id].pop(0)
voice.play(source, after=lambda x=0: check_queue(ctx, ctx.message.guild.id))