RuntimeError:超时上下文管理器应在任务[discord.py]

问题描述

这是我的一部分代码

async def tracklooper(ctx):
    no = 1
    sno = str(no)
    itimess = int(timess)
    if (no <= itimess):
        try:
            await tracklooper_count.delete()
        except:
            pass
        if voice.is_playing():
            voice.stop()
        voice.play(discord.FFmpegPCMAudio(audio),after=lambda e: asyncio.run(tracklooper(ctx)))
        tracklooper_count = await ctx.send("Playing "+vTT+" for "+sno+" time")
        no = no+1
    else:
        try:
            await tracklooper_count.delete()
        except:
            pass
        tracklooper_countt = await ctx.send("Played "+vTT+" "+no+" times")

这是错误

Traceback (most recent call last):
  File "/home/sks8gcp2/.local/lib/python3.8/site-packages/discord/player.py",line 611,in _call_after
    self.after(error)
  File "riff.py",line 205,in <lambda>
    voice.play(discord.FFmpegPCMAudio(audio),after=lambda e: asyncio.run(tracklooper(ctx)))
  File "/usr/lib/python3.8/asyncio/runners.py",line 43,in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py",line 616,in run_until_complete
    return future.result()
  File "riff.py",line 206,in tracklooper
    tracklooper_count = await ctx.send("Playing "+vTT+" for "+sno+" time")
  File "/home/sks8gcp2/.local/lib/python3.8/site-packages/discord/abc.py",line 890,in send
    data = await state.http.send_message(channel.id,content,tts=tts,embed=embed,File "/home/sks8gcp2/.local/lib/python3.8/site-packages/discord/http.py",line 185,in request
    async with self.__session.request(method,url,**kwargs) as r:
  File "/home/sks8gcp2/.local/lib/python3.8/site-packages/aiohttp/client.py",line 1012,in __aenter__
    self._resp = await self._coro
  File "/home/sks8gcp2/.local/lib/python3.8/site-packages/aiohttp/client.py",line 426,in _request
    with timer:
  File "/home/sks8gcp2/.local/lib/python3.8/site-packages/aiohttp/helpers.py",line 579,in __enter__
    raise RuntimeError('Timeout context manager should be used '
RuntimeError: Timeout context manager should be used inside a task

在这里,我试图重复音频播放,即用户想要的次数全局变量timess包含用户想要重复播放歌曲的次数,变量vTT包含歌曲的标题。但是,这首歌曲会无限循环播放,并且在设置的时间后不会停止播放,并且代码tracklooper_count = await ctx.send("Playing "+vTT+" for "+sno+" time")仅在第一次运行时发送消息,而在第二次循环中不起作用,而是抛出上述错误。>

我的期望是重复播放歌曲所需的次数,并发送包含重复播放歌曲次数的消息,并在达到限制后停止重复播放,然后发送有关歌曲的消息已重复n次。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)