Discord.py歌曲排队系统



我正在尝试编写一个discord音乐机器人程序,它一直有效,直到我将排队系统从URL列表转换为带有歌曲名称的词典,这样我就可以显示接下来播放的内容。

当第二首歌即将播放时,我收到以下错误消息:

C:UserssammyAppDataLocalProgramsPythonPython38libsite-packagesdiscordplayer.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\Python38\lib\site-packages\discord\player.py:611:RuntimeWarning:coroutine'命令呼叫"从未被等待self.after(错误(运行时警告:启用tracemalloc以获取对象分配回溯

由于您的错误代码声明您忘记添加";等待";在第611行的开头。

C:\Users\sammy\AppData\Local\Programs\Python38\lib\site-packages\discord\player.py是脚本的文件路径

:611:是上述文件中的一行

运行时间警告:coroutine'命令调用"从未等待过self。after(error(是文件中出现错误的原因。

我希望这个分解对你有帮助,也有助于你的创业。

(通常(表示您忘记在某个地方的协程(以async开头的函数(之前使用await,这是强制性的。

最新更新