【问题标题】:RuntimeWarning When attempting to run Discord BotRuntimeWarning 尝试运行 Discord Bot 时
【发布时间】:2021-01-21 17:13:08
【问题描述】:
@client.command()
@commands.has_role("Bot Owner")
async def gstart(ctx, mins : int, *, prize: str):
    embed = discord.Embed(title="Giveaway!", description=f"{prize}", color=ctx.author.color)

    end = datetime.datetime.utcnow() + datetime.timedelta(seconds=mins*60)

    embed.add_field(name='Ends At:', value=f"{end} UTC")
    embed.set_footer(text=f'Ends {mins} mintues from now!')

    my_msg = await ctx.send(embed=embed)

    await my_msg.add_reaction("????")

    await  asyncio.sleep(mins*60)

    new_msg = await ctx.channel.fetch_message(my_msg.id)

    users = new_msg.reactions[0].users().flatten()
    users.pop(users.index(client.user))

    winner = random.choice(users)

    await ctx.send(f"test! {winner.mention} test {prize}!")

问题是当它过期时,我收到以下错误消息:

RuntimeWarning: Enable tracemalloc to get the object allocation traceback

可能是什么问题?

【问题讨论】:

  • 这通常是由于asyncio.sleep()函数的误用造成的。尝试删除awaitasyncio.sleep(mins*60) 之间的多余空格,因为这可能会导致问题。
  • "这通常是由于误用了 asyncio.sleep() 函数造成的。尝试删除 await 和 asyncio.sleep(mins*60) 之间的额外空间,因为这可能会导致问题。- Shunya 45 分钟前”我试着不工作 :(

标签: python-3.x discord.py


【解决方案1】:

Reaction.users 是协程,你应该等待它

users = await new_msg.reactions[0].users().flatten()

参考:

【讨论】:

    猜你喜欢
    • 2020-07-18
    • 2021-07-13
    • 1970-01-01
    • 2022-01-16
    • 2021-07-21
    • 2022-07-18
    • 2021-11-18
    • 2017-10-11
    • 1970-01-01
    相关资源
    最近更新 更多