【问题标题】:discord.py 'coroutine' object has no attribute 'reactions' errordiscord.py 'coroutine' 对象没有属性 'reactions' 错误
【发布时间】:2021-04-20 02:17:27
【问题描述】:
@bot.command()
async def voto(ctx, id, num_people):
    msg = ctx.fetch_message(id)
    winners = []
    total_users = []
    reactions = msg.reactions
    for reaction in reactions:
        users = await reaction.users().flatten()
        for user in users:
            total_users.append(user)
    for i in range(num_people):
        winners.append(i.name)
    winners_msg = '\n'.join(winners)
    await ctx.send(f"{winners_msg}\nHas won")

我在上面的代码中得到以下错误

  File ".\Testing.py", line 24, in voto
    reactions = msg.reactions
AttributeError: 'coroutine' object has no attribute 'reactions'

The above exception was the direct cause of the following exception:

RuntimeWarning: Enable tracemalloc to get the object allocation traceback

我想修复但我得到一个错误 请帮帮我

我用了翻译器

【问题讨论】:

    标签: python python-3.x discord discord.py


    【解决方案1】:

    在你的代码中ctx.fetch_message(id) 是一个协程,所以应该等待它,这就是你得到的错误。

    将该行替换为:

    msg = await ctx.fetch_message(id)

    【讨论】:

    • for i in range(num_people): TypeError: 'str' object cannot be interpreted as an integer 我收到了这个错误
    • 使用for in in range(int(num_people))。尽管最佳实践是具有更明确的功能:async def voto(ctx, id: int, num_people: int):
    猜你喜欢
    • 2021-07-30
    • 2022-12-15
    • 1970-01-01
    • 1970-01-01
    • 2020-07-19
    • 2020-12-17
    • 2021-07-27
    • 2021-01-05
    • 2021-03-06
    相关资源
    最近更新 更多