RuntimeWarning:从未等待协程 'my_after' (discord.py)
RuntimeWarning: coroutine 'my_after' was never awaited (discord.py)
伙计们。我的代码给出了错误“RuntimeWarning:coroutine 'my_after' was never awaited”。我正在使用 my_after 和 serverQueue 函数在我的音乐机器人中创建一个队列。问题出现在“voice.play (FFmpegPCMAudio (URL, ** FFMPEG_OPTIONS), after = lambda e: my_after (voice, message))”。只有当队列中有一首歌曲时,一切才能正常工作。其余的应该自动从队列中加载,这不会发生。当一首歌曲结束时,由于错误无法播放下一首歌曲。但如果您使用“& skip”命令,队列中的下一首歌曲将开始播放。
async def play(video_link, voice, message):
with YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(video_link, download = False)
print(info.get('title'))
URL = info['formats'][0]['url']
voice.play(FFmpegPCMAudio(URL, **FFMPEG_OPTIONS), after = lambda e: my_after(voice, message))
voice.is_playing()
await message.channel.send('**Now playing** - ' + info.get('title'))
queue = []
async def my_after(voice, message):
coro = await musicQueue(voice, message)
await asyncio.run_coroutine_threadsafe(coro).result()
async def serverQueue(voice, message):
if ( queue != [] and not voice.is_playing() ):
await play(queue.pop(0), voice, message)
async def skip(voice, message):
voice.stop()
await serverQueue(voice, message)
@client.event
async def on_message(message):
if message.author == client.user:
return
voice = get(client.voice_clients, guild=message.channel.guild)
if message.content.startswith('&' + 'join'):
await join(message)
if message.content.startswith('&' + 'play'):
arg = message.content[:0] + message.content[6:]
await join(message)
voice = get(client.voice_clients, guild=message.channel.guild)
if arg.startswith('https:'):
video_link = arg
if voice.is_playing() == False:
await play(video_link, voice, message)
else:
await message.channel.send('added to queue')
queue.append(video_link)
错误解释了它。您没有等待异步函数。
改变这个:
after = lambda e: my_after(voice, message))
为此:
after = lambda e: asyncio.run(my_after(voice, message))
伙计们。我的代码给出了错误“RuntimeWarning:coroutine 'my_after' was never awaited”。我正在使用 my_after 和 serverQueue 函数在我的音乐机器人中创建一个队列。问题出现在“voice.play (FFmpegPCMAudio (URL, ** FFMPEG_OPTIONS), after = lambda e: my_after (voice, message))”。只有当队列中有一首歌曲时,一切才能正常工作。其余的应该自动从队列中加载,这不会发生。当一首歌曲结束时,由于错误无法播放下一首歌曲。但如果您使用“& skip”命令,队列中的下一首歌曲将开始播放。
async def play(video_link, voice, message):
with YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(video_link, download = False)
print(info.get('title'))
URL = info['formats'][0]['url']
voice.play(FFmpegPCMAudio(URL, **FFMPEG_OPTIONS), after = lambda e: my_after(voice, message))
voice.is_playing()
await message.channel.send('**Now playing** - ' + info.get('title'))
queue = []
async def my_after(voice, message):
coro = await musicQueue(voice, message)
await asyncio.run_coroutine_threadsafe(coro).result()
async def serverQueue(voice, message):
if ( queue != [] and not voice.is_playing() ):
await play(queue.pop(0), voice, message)
async def skip(voice, message):
voice.stop()
await serverQueue(voice, message)
@client.event
async def on_message(message):
if message.author == client.user:
return
voice = get(client.voice_clients, guild=message.channel.guild)
if message.content.startswith('&' + 'join'):
await join(message)
if message.content.startswith('&' + 'play'):
arg = message.content[:0] + message.content[6:]
await join(message)
voice = get(client.voice_clients, guild=message.channel.guild)
if arg.startswith('https:'):
video_link = arg
if voice.is_playing() == False:
await play(video_link, voice, message)
else:
await message.channel.send('added to queue')
queue.append(video_link)
错误解释了它。您没有等待异步函数。
改变这个:
after = lambda e: my_after(voice, message))
为此:
after = lambda e: asyncio.run(my_after(voice, message))