0
@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

我想修复但我收到错误请帮助我

我用了翻译器

4

1 回答 1

2

在您的代码ctx.fetch_message(id)中是一个协程,因此应该等待它,这就是您遇到的错误。

将该行替换为:

msg = await ctx.fetch_message(id)

于 2021-01-15T07:08:14.220 回答