Need help Discord bot queue(需要帮助 Discord 机器人队列)
问题描述
我一直在尝试为不和谐机器人创建队列,而我的 >q
命令基本上可以作为 join
play
queue
同时进行.问题是它只能同时排队 2 首歌曲,所以我需要帮助让它排队多首歌曲
i've been tryin to make a queue for discord bot and my >q
command basicaly work as join
play
queue
at the same time. The problem is it only queues 2 songs at the same time so I need help making it queue multi songs
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+ 首歌曲,添加 after=lambda x=0:check_queue(ctx, ctx.message.guild.id)
在 check_queue
里面稍微改一下,就变成这样了
after I do some study and search I figure out an easy way to make the queue loop 2+ songs, add after=lambda x=0: check_queue(ctx, ctx.message.guild.id)
inside check_queue
and change a little and it will look like this
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 机器人队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:需要帮助 Discord 机器人队列
基础教程推荐
- 筛选NumPy数组 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01