python-3.x - Discord.py歌曲排队系统
问题描述
我正在尝试编写一个不和谐的音乐机器人,它一直在工作,直到我将排队系统从 URL 列表转换为带有歌曲名称的字典,这样我就可以显示接下来播放的内容。
当第二首歌曲即将播放时,我收到以下错误消息:
C:\Users\sammy\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\player.py:611: RuntimeWarning: coroutine 'Command.__call__' was never awaited
self.after(error)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
这是代码,我已经对其进行了一些修剪,使其不会超长:
global ydl_opts
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
from discord.utils import get
global voice
global queue_list
queue_list = {}
def queue():
global queue_list
print("hi")
print(len(queue_list))
if len(queue_list) != 0:
keys = list(queue_list.keys())
values = list(queue_list.values())
print("AAAAAAAAAAAAA: " + str(values[0]))
play_url(str(values[0]))
print("AAAAAAAAAAAAA2: " + str(queue_list[keys[0]]))
del queue_list[keys[0]]
print(str(queue_list))
def play_url(url):
try:
os.remove("song.mp3")
except:pass
url = str(url)
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
for file in os.listdir("./"):
if file.endswith(".mp3"):
os.rename(file, "song.mp3")
voice.play(discord.FFmpegPCMAudio("song.mp3"), after=lambda e: queue())
voice.source = discord.PCMVolumeTransformer(voice.source)
voice.source.volume = 0.07
@client.command()
async def play(ctx, curl):
#global voice
try:
global voice
voice = await ctx.message.author.voice.channel.connect()
except:pass
if voice.is_playing() == False:
print("first")
song_there = os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
except PermissionError:
return
#voice = get(client.voice_clients, guild=ctx.guild)
play_url(curl)
elif voice and voice.is_playing():
print("next")
info_dict = YoutubeDL(ydl_opts).extract_info(curl, download=False)#youtube dl attribute settings are needed
#print(info_dict['title'])
if info_dict.get('title', None) in queue_list:
queue_list[str(info_dict['title']) + str(random.randint())] = curl
else:
queue_list[str(info_dict['title'])] = curl
#print(str(queue_list))
pass
@client.command(pass_context=True)
async def pause(ctx):
#voice = get(ctx.client.voice_clients, guild=ctx.guild)
#voice = await ctx.message.author.voice.channel.connect()
if voice and voice.is_playing():
voice.pause()
@client.command(pass_context=True)
async def resume(ctx):
if voice and voice.is_paused():
voice.resume()
@client.command(pass_context=True)
async def stop(ctx):
global queue_list
queue_list = []
if voice and voice.is_playing():
voice.stop()
@client.command(pass_context=True)
async def skip(ctx):
voice.stop()
try:
os.remove("song.mp3")
except:pass
play_url(queue_list[0])
@client.command(pass_context=True)
async def queue(ctx):
values = list(queue_list.values())
keys = list(queue_list.keys())
await ctx.send("*Up Next:*")
for i in range(len(keys)):
info_dict = YoutubeDL(ydl_opts).extract_info(values[i], download=False)
message = "**" + str(i + 1) + ".** " + str(keys[i]) + " (" + str(info_dict['duration']) + ")"
await ctx.send(message)
client.run(TOKEN)
解决方案
C:\Users\sammy\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\player.py:611: RuntimeWarning: coroutine 'Command. call ' 从未等待 self.after(error) RuntimeWarning: Enable tracemalloc to get the object allocation traceback
正如您的错误代码所述,您忘记在第 611 行的开头添加“等待”。
C:\Users\sammy\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\player.py是脚本的文件路径
:611:是上述文件中的行
运行时警告:协程'命令。call ' 从未等待 self.after(error)是文件中出了什么问题。
我希望此细分对您有所帮助并有助于您的事业。
推荐阅读
- javascript - 如何添加添加行按钮 React?
- javascript - 如何在没有 window.scrollBy(x, y) 的情况下上下滚动 HTML DOM(我需要在一个元素中向下滚动)
- sql - 我想通过在 sql 中的现有值之间插入 0(零)来更新表的列
- windows - Saltstack 对状态变化的操作
- java - 将两个 A5 横向 PDF 合并为单个 A4 纵向 PDF
- python-3.x - 在 while 循环中陷入 if 语句。我该如何退出?
- view - Odoo 12:根据条件更改表单视图中的字段颜色(字体颜色)
- django - 当表单字段为 ModelMultipleChoiceField 时,如何在视图中接收 modelform_instance.cleaned_data['ManyToMany field']?
- c# - 使用join会抛出无法调试的异常
- c# - 任何 XML 文件的 SSIS 脚本任务检查文件夹