【问题标题】:RuntimeWarning: couroutine 'Command.__call__' was never awaitedRuntimeWarning:从未等待 couroutine 'Command.__call__'
【发布时间】:2022-01-16 02:19:45
【问题描述】:

我遇到问题的命令:

@bot.command()
async def auction(ctx, starting, items, items2):
    price = starting

    embed1=discord.Embed(title=f'**__Auction Starting!__**', description=f'**{ctx.author}** is starting an auction for **{items} {items2}**.\nThe starting price is **⏣ {starting}**.', color=discord.Color.gold())
    await ctx.send(embed=embed1)
    embed2=discord.Embed(title=f'**__Current Price__**', description=f'The price is currently:\n**⏣ {price}**.', color=discord.Color.gold())
    message1 = await ctx.send(embed=embed2)

    end = False
    while not end:
      try:
        user = await bot.wait_for('message', check=check, timeout=3600)
        bid = int(user.content)
        if int(bid) > 0:
          price += f"{bid}"
          await message1.edit(embed=embed2)
      except asyncio.TimeoutError:
        end = True

错误是:

RuntimeWarning: couroutine 'Command.__call__' was never awaited.
  super().dispatch(event_name, *args, **kwargs)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback.

如果需要,这里是完整的代码: https://mystb.in/MechanicsRoommatePhone.python

感谢您的回答!

【问题讨论】:

    标签: python discord discord.py python-asyncio


    【解决方案1】:

    您的问题很可能出在check() 函数中(此处未显示)。

    确保将您的 check() 函数定义为同步函数,而不是 async

    def check(m):

    如果您确实需要 check() 作为异步函数,您将需要使用 asyncio.create_task()(在 Python >=3.7 中)或 loop.create_task()(在 Python >=3.4.2 中)或 @ 987654323@(在 Python 中 >=3.4.4)。

    请注意asyncio.create_task()(和其他函数)将立即返回,并且不会等待任务完成。该任务将计划在其他地方的一个或多个awaits 之后运行。

    【讨论】:

      猜你喜欢
      • 2021-02-06
      • 2018-10-26
      • 1970-01-01
      • 2021-10-22
      • 2019-12-15
      • 2021-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多